SET

The SET clause updates labels and properties on vertices and edges.

Note!
In YMatrix AGE, the underlying MPP storage requires data motion, which partitions the query into multiple slices. Because YMatrix permits only one write slice per transaction, using multiple write operators in a single Cypher statement may trigger:
ERROR: AssignTransactionId() called by Segment Reader process.
Therefore, minimize concurrent use of multiple write operators (e.g., CREATE, SET, REMOVE, MERGE) within a single Cypher statement.

Terminal SET Clause

A SET clause not followed by another clause is terminal. When a Cypher query ends with a terminal clause, the cypher() function returns no result rows. However, the cypher() function still requires a column definition list. When the query ends in a terminal clause, define a dummy column in the list — the variable yields no data.

Setting Properties

To set a property on a vertex or edge, use SET.

Query

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

The query applies the change but returns no rows.

Result

v
(0 rows)

Returning the Updated Vertex

Use the following query to update and return a single vertex:

Query

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

Returns the updated vertex.

Result

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

Removing Properties

Although REMOVE is the standard way to delete a property, SET can also be used — for example, when the property value originates from a parameter.

Query

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

Returns the vertex with the name property removed.

Result

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

Setting Multiple Properties in a Single SET Clause

To set multiple properties in one query, separate assignments with commas.

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)

Setting Multiple Properties Using Multiple SET Clauses

Multiple SET clauses may also be used to assign properties.

Prefer setting multiple properties in a single SET clause rather than splitting them across multiple SET clauses.

Query

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

Result

v
{"id": 281474976710661, "label": "", "properties": {"name": "Andres", "surname": "Taylor", "position": "Developer"}}::vertex
(1 row)