14.4. Set

14.4.1. Set a property
14.4.2. Remove a property
14.4.3. Copying properties between nodes and relationships
14.4.4. Set a label on a node
14.4.5. Set multiple labels on a node

Updating properties and labels on nodes and relationships is done with the SET clause. SET properties can also be used with maps from parameters.

[Note]Note

Setting labels on a node is an idempotent operations - if you try to set a label on a node that already has that label on it, nothing happens. The query statistics will tell you if something needed to be done or not.

The examples use this graph as a starting point:

cypher-set-graph.svg

14.4.1. Set a property

To set a property on a node or relationship, use SET.

Query. 

MATCH n
WHERE n.name='Andres'
SET n.surname = 'Taylor'
RETURN n

The newly changed node is returned by the query.

Result

n
1 row
Properties set: 1

Node[4]{awesome:true,age:36,name:"Andres",surname:"Taylor"}


14.4.2. Remove a property

Normally you remove a property by using delete, but it’s sometimes handy to do it using the SET command. One example is if the property comes from a parameter.

Query. 

MATCH n
WHERE n.name='Andres'
SET n.name = NULL RETURN n

The node is returned by the query, and the name property is now missing.

Result

n
1 row
Properties set: 1

Node[4]{awesome:true,age:36}


14.4.3. Copying properties between nodes and relationships

You can also use SET to copy all properties from one graph element to another. Remember that doing this will remove all other properties on the receiving graph element.

Query. 

MATCH at, pn
WHERE at.name='Andres' AND pn.name='Peter'
SET at = pn
RETURN at, pn

The Andres node has had all it’s properties replaced by the properties in the Peter node.

Result

atpn
2 rows
Properties set: 5

Node[4]{age:34,name:"Peter"}

Node[3]{age:34,name:"Peter"}

Node[4]{age:34,name:"Peter"}

Node[4]{age:34,name:"Peter"}


14.4.4. Set a label on a node

To set a label on a node, use SET.

Query. 

MATCH n
WHERE n.name='Stefan'
SET n :German
RETURN n

The newly labeled node is returned by the query.

Result

n
1 row
Labels added: 1

Node[2]{name:"Stefan"}


14.4.5. Set multiple labels on a node

To set multiple labels on a node, use SET and separate the different labels using :.

Query. 

MATCH n
WHERE n.name='Emil'
SET n :Swedish:Bossman
RETURN n

The newly labeled node is returned by the query.

Result

n
1 row
Labels added: 2

Node[1]{name:"Emil"}