Skip to content

Commit 07d64b3

Browse files
committed
Support most a_expr Comparison Operators
Basic Math Functions
1 parent fe4142f commit 07d64b3

File tree

3 files changed

+79
-17
lines changed

3 files changed

+79
-17
lines changed

regress/expected/new_cypher.out

+10
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ SELECT a.j FROM tst AS a(j);
142142
ERROR: syntax error at or near "("
143143
LINE 1: SELECT a.j FROM tst AS a(j);
144144
^
145+
SELECT i FROM tst WHERE i = i;
146+
i
147+
---
148+
(0 rows)
149+
150+
SELECT i FROM tst WHERE i > i;
151+
i
152+
---
153+
(0 rows)
154+
145155
--SELECT a.j FROM tst a(j);
146156
DROP GRAPH new_cypher CASCADE;
147157
NOTICE: drop cascades to 2 other objects

regress/sql/new_cypher.sql

+3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ SELECT a.i FROM tst AS a;
7373
SELECT a.i FROM tst a;
7474

7575
SELECT a.j FROM tst AS a(j);
76+
77+
SELECT i FROM tst WHERE i = i;
78+
SELECT i FROM tst WHERE i > i;
7679
--SELECT a.j FROM tst a(j);
7780

7881

src/backend/parser/cypher_gram.y

+66-17
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@
133133
%type <node> select_no_parens select_with_parens select_clause
134134
simple_select
135135

136-
%type <node> a_expr b_expr c_expr indirection_el
136+
%type <node> where_clause
137+
a_expr b_expr c_expr indirection_el
137138
columnref
138139
%type <target> target_el
139140
%type <node> table_ref
@@ -175,7 +176,7 @@
175176
%type <list> yield_item_list
176177

177178
/* common */
178-
%type <node> where_opt
179+
%type <node> cypher_where_opt
179180

180181
/* pattern */
181182
%type <list> pattern simple_path_opt_parens simple_path
@@ -216,7 +217,6 @@
216217
opt_collate
217218
indirection
218219
any_name attrs opt_class
219-
220220
%type <defelt> def_elem reloption_elem
221221
%type <string> Sconst
222222
%type <string> ColId ColLabel
@@ -302,6 +302,11 @@ makeColumnRef(char *colname, List *indirection,
302302
int location, ag_scanner_t yyscanner);
303303
static List *
304304
check_indirection(List *indirection, ag_scanner_t yyscanner);
305+
306+
static Node *
307+
doNegate(Node *n, int location);
308+
309+
305310
%}
306311
%%
307312

@@ -509,7 +514,7 @@ select_clause:
509514
simple_select:
510515
SELECT opt_all_clause opt_target_list
511516
//into_clause
512-
from_clause //where_clause
517+
from_clause where_clause
513518
//group_clause having_clause window_clause
514519
{
515520
SelectStmt *n = makeNode(SelectStmt);
@@ -850,6 +855,11 @@ opt_alias_clause: alias_clause { $$ = $1; }
850855
;
851856

852857

858+
where_clause:
859+
WHERE a_expr { $$ = $2; }
860+
| /*EMPTY*/ { $$ = NULL; }
861+
;
862+
853863
CreateGraphStmt:
854864
CREATE GRAPH IDENTIFIER
855865
{
@@ -919,7 +929,7 @@ CreateTableStmt:
919929
;
920930

921931
call_stmt:
922-
CALL expr_func_norm AS var_name where_opt
932+
CALL expr_func_norm AS var_name cypher_where_opt
923933
{
924934
cypher_call *call = make_ag_node(cypher_call);
925935
call->cck = CCK_FUNCTION;
@@ -931,7 +941,7 @@ call_stmt:
931941
call->query_tree = NULL;
932942
$$ = call;
933943
}
934-
| CALL expr_func_norm YIELD yield_item_list where_opt
944+
| CALL expr_func_norm YIELD yield_item_list cypher_where_opt
935945
{
936946
cypher_call *call = make_ag_node(cypher_call);
937947
call->cck = CCK_FUNCTION;
@@ -1409,7 +1419,7 @@ limit_opt:
14091419
;
14101420

14111421
with:
1412-
WITH DISTINCT return_item_list where_opt group_by_opt having_opt window_clause order_by_opt skip_opt limit_opt
1422+
WITH DISTINCT return_item_list cypher_where_opt group_by_opt having_opt window_clause order_by_opt skip_opt limit_opt
14131423
{
14141424
ListCell *li;
14151425
cypher_with *n;
@@ -1443,7 +1453,7 @@ with:
14431453

14441454
$$ = (Node *)n;
14451455
}
1446-
| WITH return_item_list where_opt group_by_opt having_opt window_clause order_by_opt skip_opt limit_opt
1456+
| WITH return_item_list cypher_where_opt group_by_opt having_opt window_clause order_by_opt skip_opt limit_opt
14471457
{
14481458
ListCell *li;
14491459
cypher_with *n;
@@ -1484,7 +1494,7 @@ with:
14841494
*/
14851495

14861496
match:
1487-
optional_opt MATCH pattern where_opt order_by_opt
1497+
optional_opt MATCH pattern cypher_where_opt order_by_opt
14881498
{
14891499
cypher_match *n;
14901500

@@ -1895,10 +1905,10 @@ a_expr: c_expr { $$ = $1; }
18951905
list_make2($5, $1),
18961906
COERCE_SQL_SYNTAX,
18971907
@2);
1898-
}
1899-
| '+' a_expr %prec UMINUS
1908+
}*/
1909+
| '+' a_expr // %prec ;
19001910
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
1901-
| '-' a_expr %prec UMINUS
1911+
| '-' a_expr // %prec UMINUS
19021912
{ $$ = doNegate($2, @1); }
19031913
| a_expr '+' a_expr
19041914
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
@@ -1918,16 +1928,16 @@ a_expr: c_expr { $$ = $1; }
19181928
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
19191929
| a_expr '=' a_expr
19201930
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
1921-
| a_expr LESS_EQUALS a_expr
1931+
/*| a_expr LESS_EQUALS a_expr
19221932
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
19231933
| a_expr GREATER_EQUALS a_expr
19241934
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
19251935
| a_expr NOT_EQUALS a_expr
19261936
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
19271937
1928-
| a_expr qual_Op a_expr %prec Op
1938+
| a_expr qual_Op a_expr // %prec Op
19291939
{ $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
1930-
| qual_Op a_expr %prec Op
1940+
| qual_Op a_expr // %prec Op
19311941
{ $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
19321942
19331943
| a_expr AND a_expr
@@ -2808,7 +2818,7 @@ merge:
28082818
* common
28092819
*/
28102820

2811-
where_opt:
2821+
cypher_where_opt:
28122822
/* empty */
28132823
{
28142824
$$ = NULL;
@@ -4405,4 +4415,43 @@ check_indirection(List *indirection, ag_scanner_t yyscanner)
44054415
}
44064416
}
44074417
return indirection;
4408-
}
4418+
}
4419+
4420+
/* doNegate()
4421+
* Handle negation of a numeric constant.
4422+
*
4423+
* Formerly, we did this here because the optimizer couldn't cope with
4424+
* indexquals that looked like "var = -4" --- it wants "var = const"
4425+
* and a unary minus operator applied to a constant didn't qualify.
4426+
* As of Postgres 7.0, that problem doesn't exist anymore because there
4427+
* is a constant-subexpression simplifier in the optimizer. However,
4428+
* there's still a good reason for doing this here, which is that we can
4429+
* postpone committing to a particular internal representation for simple
4430+
* negative constants. It's better to leave "-123.456" in string form
4431+
* until we know what the desired type is.
4432+
*/
4433+
static Node *
4434+
doNegate(Node *n, int location)
4435+
{
4436+
if (IsA(n, A_Const))
4437+
{
4438+
A_Const *con = (A_Const *)n;
4439+
4440+
/* report the constant's location as that of the '-' sign */
4441+
con->location = location;
4442+
4443+
if (con->val.type == T_Integer)
4444+
{
4445+
con->val.val.ival = -con->val.val.ival;
4446+
return n;
4447+
}
4448+
if (con->val.type == T_Float)
4449+
{
4450+
doNegateFloat(&con->val);
4451+
return n;
4452+
}
4453+
}
4454+
4455+
return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
4456+
}
4457+

0 commit comments

Comments
 (0)