Skip to content

Commit 26d1797

Browse files
committed
Support HAVING Clause
1 parent a1cba4e commit 26d1797

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

regress/expected/new_cypher.out

+5
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ SELECT a.i as j FROM tst a GROUP BY a.i;
168168
---
169169
(0 rows)
170170

171+
SELECT a.i as j FROM tst a GROUP BY a.i HAVING a.i = a.i;
172+
j
173+
---
174+
(0 rows)
175+
171176
DROP GRAPH new_cypher CASCADE;
172177
NOTICE: drop cascades to 2 other objects
173178
DETAIL: drop cascades to table new_cypher._ag_label_vertex

regress/sql/new_cypher.sql

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ SELECT a.* FROM tst as a;
8585

8686
SELECT a.i as j FROM tst a GROUP BY a.i;
8787

88+
SELECT a.i as j FROM tst a GROUP BY a.i HAVING a.i = a.i;
8889

8990
DROP GRAPH new_cypher CASCADE;
9091
DROP GRAPH new_cypher_2 CASCADE;

src/backend/parser/cypher_gram.y

+9-3
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ typedef struct GroupClause
144144

145145
%type <node> where_clause
146146
a_expr b_expr c_expr indirection_el
147-
columnref
147+
columnref having_clause
148148

149149
%type <integer> set_quantifier
150150
%type <target> target_el
@@ -530,7 +530,7 @@ simple_select:
530530
SELECT opt_all_clause opt_target_list
531531
//into_clause
532532
from_clause where_clause group_clause
533-
group_clause //having_clause window_clause
533+
having_clause //window_clause
534534
{
535535
SelectStmt *n = makeNode(SelectStmt);
536536
/*n->targetList = $3;
@@ -547,7 +547,7 @@ simple_select:
547547
n->whereClause = $5;
548548
n->groupClause = ($6)->list;
549549
n->groupDistinct = ($6)->distinct;
550-
n->havingClause = NULL;
550+
n->havingClause = $7;
551551
n->windowClause = NULL;
552552
$$ = (Node *)n;
553553
}
@@ -1295,6 +1295,12 @@ empty_grouping_set:
12951295
}
12961296
;
12971297

1298+
having_clause:
1299+
HAVING a_expr { $$ = $2; }
1300+
| /*EMPTY*/ { $$ = NULL; }
1301+
;
1302+
1303+
12981304
return:
12991305
RETURN DISTINCT return_item_list group_by_opt having_opt window_clause order_by_opt skip_opt limit_opt
13001306
{

0 commit comments

Comments
 (0)