Set
The SET
clause is similar to that in SQL. It allows updating properties of node or relationship records (possibly NULL
).
We will use the example database for demonstration, whose schema and data import commands are given here.
Set node properties
Set single label node properties
The following query sets the age property of the User node with name Adam to 50 (which is 30 in the original database).
MATCH (u:User)WHERE u.name = 'Adam'SET u.age = 50RETURN u.*;
ββββββββββ¬βββββββββ u.name β u.age ββ STRING β INT64 βββββββββββΌββββββββ€β Adam β 50 βββββββββββ΄ββββββββ
Similarly the following sets Adamβs age property to NULL. Query:
MATCH (u:User)WHERE u.name = 'Adam'SET u.age = NULLRETURN u.*;
ββββββββββ¬βββββββββ u.name β u.age ββ STRING β INT64 βββββββββββΌββββββββ€β Adam β βββββββββββ΄ββββββββ
Set multi label node properties
Kuzu also supports updating node properties with multi-label nodes.
MATCH (u)SET u.population = 0RETURN label(u), u.name, u.population;
ββββββββββββββββββββββββββββ¬ββββββββββββ¬ββββββββββββββββ LABEL(u._ID,[User,City]) β u.name β u.population ββ STRING β STRING β INT64 βββββββββββββββββββββββββββββΌββββββββββββΌβββββββββββββββ€β City β Waterloo β 0 ββ City β Kitchener β 0 ββ City β Guelph β 0 ββ User β Adam β ββ User β Karissa β ββ User β Zhang β ββ User β Noura β ββ User β Bob β ββ User β Alice β ββ User β Dimitri β βββββββββββββββββββββββββββββ΄ββββββββββββ΄βββββββββββββββ
Note that the node table User
doesnβt contain the population
property, so tuples belonging to the User
table (showing NULL
in the output) are ignored during SET
operations.
Set relationship properties
Set single label relationship properties
The following query sets the since
property of the Follows relationship(From Adam to Karissa) to 2012 (which is 2020 in the original database).
MATCH (u0:User)-[f:Follows]->(u1:User)WHERE u0.name = 'Adam' AND u1.name = 'Karissa'SET f.since = 2012RETURN f;
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ f ββ REL ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€β (0:0)-{_LABEL: Follows, _ID: 2:0, since: 2012}->(0:1) ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Set multi label relationship properties
MATCH (u0)-[f]->()WHERE u0.name = 'Adam'SET f.since = 1999RETURN f;
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ f ββ REL ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€β (0:0)-{_LABEL: Follows, _ID: 2:0, since: 1999}->(0:1) ββ (0:0)-{_LABEL: Follows, _ID: 2:1, since: 1999}->(0:2) ββ (0:0)-{_LABEL: Follows, _ID: 2:4, since: 1999}->(0:3) ββ (0:0)-{_LABEL: LivesIn, _ID: 3:0}->(1:0) ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ