Overview
The SET
statement allows you to update, add, or remove properties on nodes and edges. These nodes or edges must first be retrieved using the MATCH
statement.
Note that the label on a node or an edge is not subject to any modification.
<set statement> ::= "SET" <set item list>
<set item list> ::= <set item> [ { "," <set item> }... ]
<set item> ::= <set property item> | <set all properties item>
<set property item> ::=
<binding variable reference> "." <property name> "=" <value expression>
<set all properties item> ::=
<binding variable reference> "=" "{" [ <property key value pair list> ] "}"
Details
- The values of system properties (
_id
,_uuid
,_from
,_to
,_from_uuid
, and_to_uuid
) cannot be modified.
Example Graph
Each of the following examples begins with this graph:
To create this graph, run the following query against an empty graph:
INSERT (rowlock:User {_id: "U01", name: "rowlock"}),
(brainy:User {_id: "U02", name: "Brainy", gender: "male"}),
(purplechalk:User {_id: "U03", name: "purplechalk", gender: "female"}),
(mochaeach:User {_id: "U04", name: "mochaeach", gender: "female"}),
(c:Club {_id: "C01"}),
(rowlock)-[:Follows {createdOn: "2024-1-5"}]->(brainy),
(purplechalk)-[:Follows {createdOn: "2024-2-1"}]->(brainy),
(mochaeach)-[:Follows {createdOn: "2024-2-10}]->(brainy),
(brainy)-[:Joins {memberNo: 1}]->(c)
Updating Properties
This query updates the property gender
for the retrieved node n
, and the property createdOn
for the retrieved edge e
.
MATCH (n:User {name: 'rowlock'})-[e:Follows]->(:User {name: 'Brainy'})
SET n.gender = 'male', e.createdOn = '2024-1-7'
RETURN n.gender, e.createdOn
Result:
n.gender | e.createdOn |
---|---|
male | 2024-01-07 00:00:00 |
Removing Properties
This query removes the value of the property gender
for the retrieved node n
.
MATCH (n:User {name: 'mochaeach'})
SET n.gender = null
RETURN n
Result: n
_id | _uuid | schema | values |
---|---|---|---|
U04 | Sys-gen | User | {name: "mochaeach", gender: null} |
Overwriting All Properties
This query overwrites all properties for the retrieved node n
with a map: updating value of the property name
, removing values of other (custom) properties.
MATCH (n:User {name: 'purplechalk'})
SET n = {name: 'MasterSwift'}
RETURN n
Result: n
_id | _uuid | schema | values |
---|---|---|---|
U03 | Sys-gen | User | {name: "MasterSwift", gender: null} |
Removing All Properties
This query removes all (custom) properties for the retrieved node n
with an empty map.
MATCH (n:User {name: 'rowlock'})
SET n = {}
RETURN n
Result: n
_id | _uuid | schema | values |
---|---|---|---|
U03 | Sys-gen | User | {name: null, gender: null} |
Updating Properties with CASE
This query assigns values to the weight
property of edges labeled Follows
, determined by their createdOn
values.
MATCH ()-[e:Follows]->()
SET e.weight = CASE
WHEN e.createdOn < '2024-1-31' THEN 10
ELSE 8
END
RETURN e
Result: e
_uuid |
_from |
_to |
_from_uuid |
_to_uuid |
schema |
values |
---|---|---|---|---|---|---|
Sys-gen | U01 | U02 | UUID of U01 | UUID of U02 | Follows | {createdOn: "2024-01-05 00:00:00", weight: 10} |
Sys-gen | U04 | U02 | UUID of U04 | UUID of U02 | Follows | {createdOn: "2024-02-10 00:00:00", weight: 8} |
Sys-gen | U03 | U02 | UUID of U03 | UUID of U02 | Follows | {createdOn: "2024-02-01 00:00:00", weight: 8} |
Mismatched Property Value and Type
This query updates the property memberNo
(int32-type) of the retrieved edge with a string.
MATCH ()-[e:Joins]->()
SET e.memberNo = 'm2'
RETURN e
Result: e
_uuid |
_from |
_to |
_from_uuid |
_to_uuid |
schema |
values |
---|---|---|---|---|---|---|
Sys-gen | C01 | U02 | UUID of C01 | UUID of U02 | Follows | {memberNo: 0} |
If the provided value is of a different type than the property type and cannot be converted to the correct type, the default value for that property type will be used instead.