Use the SET clause to update labels and properties on vertices and edges in a Cypher query.
Terminal SET clauses
A SET clause not followed by another clause is a terminal clause. When a Cypher query ends with a terminal SET, the cypher() function returns no rows. The function call still requires a column list definition — define a single column variable to satisfy the syntax requirement, but no data is returned in that variable.
Set a property
To set a property on a vertex or edge, match the target and assign the value with SET.
Example: set a property on a vertex
SELECT *
FROM cypher('graph_name', $$
MATCH (v {name: 'Andres'})
SET v.surname = 'Taylor'
$$) as (v agtype);This is a terminal SET — no RETURN clause follows, so the query returns no rows:
v
---
(0 rows)Return the updated vertex
To retrieve the vertex after updating it, add a RETURN clause after SET.
Example
SELECT *
FROM cypher('graph_name', $$
MATCH (v {name: 'Andres'})
SET v.surname = 'Taylor'
RETURN v
$$) as (v agtype);Result:
v
-----------------------------------------------------------------------------------------
{id: 3; label: 'Person'; properties: {surname:"Taylor", age:36, hungry:true}}::vertex
(1 row)Set multiple properties
To set more than one property in a single query, separate the assignments with commas.
Example
SELECT *
FROM cypher('graph_name', $$
MATCH (v {name: 'Andres'})
SET v.position = 'Developer', v.surname = 'Taylor'
RETURN v
$$) as (v agtype);Result:
v
--------------------------------------------------------------------------------------------------------------------------------
{"id": 281474976710661, "label": "", "properties": {"name": "Andres", "surname": "Taylor", "position": "Developer"}}: :vertex
(1 row)