Skip to content

Commit

Permalink
fix: Remove cypher read clause restriction.
Browse files Browse the repository at this point in the history
  • Loading branch information
emotionbug committed Dec 15, 2022
1 parent daf2dd4 commit 7d5cf94
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
15 changes: 3 additions & 12 deletions src/backend/parser/analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -3496,28 +3496,19 @@ transformCypherStmt(ParseState *pstate, CypherStmt *stmt)
{
update_type = T_CypherCreateClause;
}
if (read)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("Cypher read clauses cannot follow update clauses")));
/* todo: restriction is required? */
break;
case T_CypherDeleteClause:
case T_CypherSetClause:
if (read)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("Cypher read clauses cannot follow update clauses")));
/* todo: restriction is required? */
break;
case T_CypherMergeClause:
if (update_type == T_Invalid ||
update_type == T_CypherCreateClause)
{
update_type = T_CypherMergeClause;
}
if (read)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("Cypher read clauses cannot follow update clauses")));
/* todo: restriction is required? */
break;
case T_CypherLoadClause:
read = true;
Expand Down
5 changes: 4 additions & 1 deletion src/test/regress/expected/cypher_dml.out
Original file line number Diff line number Diff line change
Expand Up @@ -2670,7 +2670,10 @@ MATCH (a) DETACH DELETE a;
-- wrong case
MERGE (a:v1) MERGE (b:v2 {name: a.notexistent});
MERGE (a:v1) MATCH (b:v2 {name: a.name}) RETURN a, b;
ERROR: Cypher read clauses cannot follow update clauses
a | b
---+---
(0 rows)

MERGE (a:v1) MERGE (b:v2 {name: a.name}) MERGE (a);
ERROR: duplicate variable "a"
LINE 1: MERGE (a:v1) MERGE (b:v2 {name: a.name}) MERGE (a);
Expand Down
5 changes: 4 additions & 1 deletion src/test/regress/expected/cypher_eager.out
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,10 @@ MATCH (a) RETURN properties(a);
-- wrong case
MERGE (a:v1) MERGE (b:v2 {name: a.notexistent});
MERGE (a:v1) MATCH (b:v2 {name: a.name}) RETURN a, b;
ERROR: Cypher read clauses cannot follow update clauses
a | b
---+---
(0 rows)

MERGE (a:v1) MERGE (b:v2 {name: a.name}) MERGE (a);
ERROR: duplicate variable "a"
LINE 1: MERGE (a:v1) MERGE (b:v2 {name: a.name}) MERGE (a);
Expand Down
25 changes: 24 additions & 1 deletion src/test/regress/sql/cypher_dml2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,29 @@ SELECT * FROM _trigger_history;

DROP GRAPH cypher_dml2 CASCADE;

-- #589 ( Cypher read clauses cannot follow update clauses )
CREATE GRAPH cypher_dml2;
SET GRAPH_PATH to cypher_dml2;

CREATE VLABEL main;
CREATE ELABEL main2;

CREATE (n:another {id: 593}) RETURN n.id;

MERGE (n:main {id: 593})
ON CREATE SET n.id = 593
WITH n
MATCH (g: another)
WHERE g.id = 593
MERGE (g)-[:main2]->(n);

MATCH ()-[e:main2]-() RETURN e;
MATCH (g: another) RETURN g;
MATCH (g: main) RETURN g;

DROP GRAPH cypher_dml2 CASCADE;

-- fix: Includes necessary JOINs of vertices (#599)
CREATE GRAPH cypher_dml2;
SET GRAPH_PATH to cypher_dml2;

Expand All @@ -130,4 +153,4 @@ EXPLAIN VERBOSE MATCH (a)-[]-(a) RETURN a;
EXPLAIN VERBOSE MATCH (a)-[]-(a) RETURN *;
EXPLAIN VERBOSE MATCH p=(a)-[]-(a) RETURN *;

DROP GRAPH cypher_dml2 CASCADE;
DROP GRAPH cypher_dml2 CASCADE;

0 comments on commit 7d5cf94

Please sign in to comment.