4

Let's assume that a Grakn KG contains entities of type 'product' and that they are uniquely identified by the key 'id_prod'. As I understand it, the attempt to insert an instance of product with a repeated id_prod will generate an error.

Assuming that the insertion is being done through a console script, how could the previous existence of the instance be checked with graql during the insertion? And via the python client, are there any special recommendations or patterns to follow?

Jorge
  • 167
  • 8

1 Answers1

2

Your assertion is correct. At present Graql doesn't have a PUT behaviour built-in that would check for existence and insert only if not present. This is a feature that should be included in the future (I work at Grakn).

Instead, you have broadly two options:

  1. You match for concepts by their keys. If there are no results then you insert them. Then you can match insert for the keyed concepts to add relations to them etc.
  2. You first ensure that you've inserted all of the keyed concepts into the KB (may not be possible). You then make the match insert queries directly, matching for the keyed concepts, with no need for checking the keys exist
James Fletcher
  • 920
  • 11
  • 13
  • so we have to do 2 queries in order to insert if we're unsure? any idea of a timescale for the PUT behaviour? – danimal Aug 07 '20 at 14:11