Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions regress/expected/cypher_set.out
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,29 @@ $$) AS (a agtype);
{"id": 844424930131970, "label": "v", "properties": {"a": 0, "i": 50, "j": 5, "y": 50, "z": 99}}::vertex
(1 row)

SELECT * FROM cypher('cypher_set', $$
MATCH (n {j: 5})
SET n.y = 53
SET n.y = 50
SET n.z = 99
SET n.arr = [n.y, n.z]
RETURN n
$$) AS (a agtype);
a
---------------------------------------------------------------------------------------------------------------------------
{"id": 844424930131970, "label": "v", "properties": {"a": 0, "i": 50, "j": 5, "y": 50, "z": 99, "arr": [50, 99]}}::vertex
(1 row)

SELECT * FROM cypher('cypher_set', $$
MATCH (n {j: 5})
REMOVE n.arr
RETURN n
$$) AS (a agtype);
a
----------------------------------------------------------------------------------------------------------
{"id": 844424930131970, "label": "v", "properties": {"a": 0, "i": 50, "j": 5, "y": 50, "z": 99}}::vertex
(1 row)

SELECT * FROM cypher('cypher_set', $$
MATCH (n {j: 5})
RETURN n
Expand Down Expand Up @@ -221,6 +244,46 @@ $$) AS (a agtype);
{"id": 844424930131970, "label": "v", "properties": {"a": 0, "i": 50, "j": 5, "y": 2, "z": 99}}::vertex
(2 rows)

-- Test that SET works with nodes(path) and relationships(path)
SELECT * FROM cypher('cypher_set', $$
MATCH p=(n)-[e:e {j:34}]->()
WITH nodes(p) AS ns
WITH ns[0] AS n
SET n.k = 99
SET n.k = 999
RETURN n
$$) AS (a agtype);
a
-------------------------------------------------------------------------------------------------------------------
{"id": 281474976710658, "label": "", "properties": {"k": 999, "y": 1}}::vertex
{"id": 844424930131970, "label": "v", "properties": {"a": 0, "i": 50, "j": 5, "k": 999, "y": 2, "z": 99}}::vertex
(2 rows)

SELECT * FROM cypher('cypher_set', $$
MATCH p=(n)-[e:e {j:34}]->()
WITH relationships(p) AS rs
WITH rs[0] AS r
SET r.l = 99
SET r.l = 999
RETURN r
$$) AS (a agtype);
a
--------------------------------------------------------------------------------------------------------------------------------------------------
{"id": 1125899906842630, "label": "e", "end_id": 281474976710659, "start_id": 281474976710658, "properties": {"j": 34, "l": 999, "y": 99}}::edge
{"id": 1125899906842629, "label": "e", "end_id": 844424930131970, "start_id": 844424930131970, "properties": {"j": 34, "l": 999}}::edge
(2 rows)

SELECT * FROM cypher('cypher_set', $$
MATCH p=(n)-[e:e {j:34}]->()
REMOVE n.k, e.l
RETURN p
$$) AS (a agtype);
a
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[{"id": 281474976710658, "label": "", "properties": {"y": 1}}::vertex, {"id": 1125899906842630, "label": "e", "end_id": 281474976710659, "start_id": 281474976710658, "properties": {"j": 34, "y": 99}}::edge, {"id": 281474976710659, "label": "", "properties": {"y": 2}}::vertex]::path
[{"id": 844424930131970, "label": "v", "properties": {"a": 0, "i": 50, "j": 5, "y": 2, "z": 99}}::vertex, {"id": 1125899906842629, "label": "e", "end_id": 844424930131970, "start_id": 844424930131970, "properties": {"j": 34}}::edge, {"id": 844424930131970, "label": "v", "properties": {"a": 0, "i": 50, "j": 5, "y": 2, "z": 99}}::vertex]::path
(2 rows)

SELECT * FROM cypher('cypher_set', $$MATCH (n)-[]->(n) SET n.y = 99 RETURN n$$) AS (a agtype);
a
----------------------------------------------------------------------------------------------------------
Expand Down
41 changes: 41 additions & 0 deletions regress/sql/cypher_set.sql
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ SELECT * FROM cypher('cypher_set', $$
RETURN n
$$) AS (a agtype);

SELECT * FROM cypher('cypher_set', $$
MATCH (n {j: 5})
SET n.y = 53
SET n.y = 50
SET n.z = 99
SET n.arr = [n.y, n.z]
RETURN n
$$) AS (a agtype);

SELECT * FROM cypher('cypher_set', $$
MATCH (n {j: 5})
REMOVE n.arr
RETURN n
$$) AS (a agtype);

SELECT * FROM cypher('cypher_set', $$
MATCH (n {j: 5})
RETURN n
Expand Down Expand Up @@ -92,6 +107,32 @@ SELECT * FROM cypher('cypher_set', $$
RETURN n
$$) AS (a agtype);

-- Test that SET works with nodes(path) and relationships(path)

SELECT * FROM cypher('cypher_set', $$
MATCH p=(n)-[e:e {j:34}]->()
WITH nodes(p) AS ns
WITH ns[0] AS n
SET n.k = 99
SET n.k = 999
RETURN n
$$) AS (a agtype);

SELECT * FROM cypher('cypher_set', $$
MATCH p=(n)-[e:e {j:34}]->()
WITH relationships(p) AS rs
WITH rs[0] AS r
SET r.l = 99
SET r.l = 999
RETURN r
$$) AS (a agtype);

SELECT * FROM cypher('cypher_set', $$
MATCH p=(n)-[e:e {j:34}]->()
REMOVE n.k, e.l
RETURN p
$$) AS (a agtype);

SELECT * FROM cypher('cypher_set', $$MATCH (n)-[]->(n) SET n.y = 99 RETURN n$$) AS (a agtype);

SELECT * FROM cypher('cypher_set', $$MATCH (n) MATCH (n)-[]->(m) SET n.t = 150 RETURN n$$) AS (a agtype);
Expand Down
9 changes: 5 additions & 4 deletions src/backend/executor/cypher_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ static HeapTuple update_entity_tuple(ResultRelInfo *resultRelInfo,
bool update_indexes;
TM_Result result;

CommandId cid = GetCurrentCommandId(true);
ResultRelInfo *saved_resultRelInfo = estate->es_result_relation_info;
estate->es_result_relation_info = resultRelInfo;

Expand All @@ -139,7 +140,7 @@ static HeapTuple update_entity_tuple(ResultRelInfo *resultRelInfo,

result = table_tuple_update(resultRelInfo->ri_RelationDesc,
&tuple->t_self, elemTupleSlot,
GetCurrentCommandId(true),
cid,
//estate->es_output_cid,
estate->es_snapshot,// NULL,
estate->es_crosscheck_snapshot,
Expand All @@ -148,7 +149,7 @@ static HeapTuple update_entity_tuple(ResultRelInfo *resultRelInfo,

if (result == TM_SelfModified)
{
if (hufd.cmax != estate->es_output_cid)
if (hufd.cmax != cid)
{
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_DATA_CHANGE_VIOLATION),
Expand All @@ -173,11 +174,11 @@ static HeapTuple update_entity_tuple(ResultRelInfo *resultRelInfo,
ExecInsertIndexTuples(elemTupleSlot, estate, false, NULL, NIL);
}

ExecCloseIndices(resultRelInfo);
ExecCloseIndices(resultRelInfo);
}
else if (lock_result == TM_SelfModified)
{
if (hufd.cmax != estate->es_output_cid)
if (hufd.cmax != cid)
{
ereport(ERROR,
(errcode(ERRCODE_TRIGGERED_DATA_CHANGE_VIOLATION),
Expand Down