SET

The SET clause is used to update labels and properties on vertices and edges

Terminal SET clauses

A SET clause that is not followed by another clause is a terminal clause. When a cypher query ends with a terminal clause, no results will be returned from the cypher function call. However, the cypher function call still requires a column list definition. When cypher ends with a terminal node, define a single value in the column list definition: no data will be returned in this variable.

Set a property

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

Query

SELECT * 
FROM cypher('graph_name', $$
   MATCH (v {name: 'Andres'})
   SET v.surname = 'Taylor'
$$) as (v agtype);

The newly changed node is returned by the query.

Result

v
(0 rows)

Return created vertex

Creating a single vertex is done with the following query:

Query

SELECT * 
FROM cypher('graph_name', $$
    MATCH (v {name: 'Andres'})
    SET v.surname = 'Taylor'
    RETURN v
$$) as (v agtype);

The newly changed vertex is returned by the query.

Result

v
{id: 3; label: ‘Person’; properties: {surname:"Taylor", name:"Andres", age:36, hungry:true}}::vertex
(1 row)

Remove a property

Normally a property can be removed by using REMOVE, but users can also remove properties using the SET command. One example is if the property comes from a parameter.

Query

SELECT * 
FROM cypher('graph_name', $$
    MATCH (v {name: 'Andres'})
    SET v.name = NULL
    RETURN v
$$) as (v agtype);

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

Result

v
{id: 3; label: ‘Person’; properties: {surname:"Taylor", age:36, hungry:true}}::vertex
(1 row)

Set multiple properties using one SET clause

If you want to set multiple properties in one query, you can separate them with a comma.

Query

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)