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?
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:
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.match insert
queries directly, matching for the keyed concepts, with no need for checking the keys exist