How can I retrieve an instance and then update it with GRAQL?



I would like to do something really simple and I cannot find any documentation about how to do it with GRAQL. I tried several things and nothing worked - I would like to retrieve an entity instance by some attribute value, then update its value and persist it back . How is this possible with grakn / graql ?



Hello @attodorov,

we do not have update queries yet, so you will need to add the new attribute and delete the old one:

Say you want to change a person’s first name:

match $x has firstname "Robert"; insert $x has firstname "Marco";

and then delete the old attribute:

match $x has firstname $y; $y val "Robert"; delete $y;

finally remember to commit to persist changes: commit;

You can also work with IDs to avoid ambiguity:

match $x has firstname "Robert"; get;

the response will be something like: $x id V90128 isa person;

then you can:

match $x id V90128; insert $x has firstname "Marco";
match $x id V90128 has firstname $y; $y val "Robert"; delete $y;