Skip to content

Commit 688de90

Browse files
committed
Support Set Operators for SELECT Stmts
1 parent 55ce4e3 commit 688de90

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

regress/expected/new_cypher.out

+21
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,27 @@ SELECT sum(salary) OVER w, avg(salary) OVER w
184184
ERROR: syntax error at or near "("
185185
LINE 1: SELECT sum(salary) OVER w, avg(salary) OVER w
186186
^
187+
SELECT a.i FROM tst a
188+
UNION
189+
SELECT a.i FROM tst a;
190+
i
191+
---
192+
(0 rows)
193+
194+
SELECT a.i FROM tst a
195+
EXCEPT
196+
SELECT a.i FROM tst a;
197+
i
198+
---
199+
(0 rows)
200+
201+
SELECT a.i FROM tst a
202+
INTERSECT
203+
SELECT a.i FROM tst a;
204+
i
205+
---
206+
(0 rows)
207+
187208
DROP GRAPH new_cypher CASCADE;
188209
NOTICE: drop cascades to 2 other objects
189210
DETAIL: drop cascades to table new_cypher._ag_label_vertex

regress/sql/new_cypher.sql

+12
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,17 @@ SELECT sum(salary) OVER w, avg(salary) OVER w
9292
FROM empsalary
9393
WINDOW w AS (PARTITION BY i ORDER BY i DESC);
9494

95+
SELECT a.i FROM tst a
96+
UNION
97+
SELECT a.i FROM tst a;
98+
99+
SELECT a.i FROM tst a
100+
EXCEPT
101+
SELECT a.i FROM tst a;
102+
103+
SELECT a.i FROM tst a
104+
INTERSECT
105+
SELECT a.i FROM tst a;
106+
95107
DROP GRAPH new_cypher CASCADE;
96108
DROP GRAPH new_cypher_2 CASCADE;

src/backend/parser/cypher_gram.y

+15-2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ typedef struct GroupClause
8282
List *list;
8383
} GroupClause;
8484

85+
static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
8586
static void insertSelectOptions(SelectStmt *stmt,
8687
List *sortClause, List *lockingClause,
8788
SelectLimit *limitClause,
@@ -615,7 +616,7 @@ simple_select:
615616
n->targetList = list_make1(rt);
616617
n->fromClause = list_make1($2);
617618
$$ = (Node *)n;
618-
}
619+
}*/
619620
| select_clause UNION set_quantifier select_clause
620621
{
621622
$$ = makeSetOp(SETOP_UNION, $3 == SET_QUANTIFIER_ALL, $1, $4);
@@ -627,7 +628,7 @@ simple_select:
627628
| select_clause EXCEPT set_quantifier select_clause
628629
{
629630
$$ = makeSetOp(SETOP_EXCEPT, $3 == SET_QUANTIFIER_ALL, $1, $4);
630-
}*/
631+
}
631632
;
632633

633634

@@ -4696,3 +4697,15 @@ insertSelectOptions(SelectStmt *stmt,
46964697
stmt->withClause = withClause;
46974698
}
46984699
}
4700+
4701+
static Node *
4702+
makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
4703+
{
4704+
SelectStmt *n = makeNode(SelectStmt);
4705+
4706+
n->op = op;
4707+
n->all = all;
4708+
n->larg = (SelectStmt *) larg;
4709+
n->rarg = (SelectStmt *) rarg;
4710+
return (Node *) n;
4711+
}

0 commit comments

Comments
 (0)