diff --git a/regress/expected/cypher_set.out b/regress/expected/cypher_set.out index 99954c312..c6eaa6932 100644 --- a/regress/expected/cypher_set.out +++ b/regress/expected/cypher_set.out @@ -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 @@ -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 ---------------------------------------------------------------------------------------------------------- diff --git a/regress/sql/cypher_set.sql b/regress/sql/cypher_set.sql index a2b36a0a3..2b1354edb 100644 --- a/regress/sql/cypher_set.sql +++ b/regress/sql/cypher_set.sql @@ -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 @@ -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); diff --git a/src/backend/executor/cypher_set.c b/src/backend/executor/cypher_set.c index ea9f0bc6f..3fb98602a 100644 --- a/src/backend/executor/cypher_set.c +++ b/src/backend/executor/cypher_set.c @@ -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; @@ -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, @@ -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), @@ -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),