133
133
%type <node> select_no_parens select_with_parens select_clause
134
134
simple_select
135
135
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
137
138
columnref
138
139
%type <target> target_el
139
140
%type <node> table_ref
175
176
%type <list> yield_item_list
176
177
177
178
/* common */
178
- %type <node> where_opt
179
+ %type <node> cypher_where_opt
179
180
180
181
/* pattern */
181
182
%type <list> pattern simple_path_opt_parens simple_path
216
217
opt_collate
217
218
indirection
218
219
any_name attrs opt_class
219
-
220
220
%type <defelt> def_elem reloption_elem
221
221
%type <string> Sconst
222
222
%type <string> ColId ColLabel
@@ -302,6 +302,11 @@ makeColumnRef(char *colname, List *indirection,
302
302
int location, ag_scanner_t yyscanner);
303
303
static List *
304
304
check_indirection (List *indirection, ag_scanner_t yyscanner);
305
+
306
+ static Node *
307
+ doNegate (Node *n, int location);
308
+
309
+
305
310
%}
306
311
%%
307
312
@@ -509,7 +514,7 @@ select_clause:
509
514
simple_select :
510
515
SELECT opt_all_clause opt_target_list
511
516
//into_clause
512
- from_clause // where_clause
517
+ from_clause where_clause
513
518
//group_clause having_clause window_clause
514
519
{
515
520
SelectStmt *n = makeNode(SelectStmt);
@@ -850,6 +855,11 @@ opt_alias_clause: alias_clause { $$ = $1; }
850
855
;
851
856
852
857
858
+ where_clause :
859
+ WHERE a_expr { $$ = $2 ; }
860
+ | /* EMPTY*/ { $$ = NULL ; }
861
+ ;
862
+
853
863
CreateGraphStmt :
854
864
CREATE GRAPH IDENTIFIER
855
865
{
@@ -919,7 +929,7 @@ CreateTableStmt:
919
929
;
920
930
921
931
call_stmt :
922
- CALL expr_func_norm AS var_name where_opt
932
+ CALL expr_func_norm AS var_name cypher_where_opt
923
933
{
924
934
cypher_call *call = make_ag_node(cypher_call);
925
935
call->cck = CCK_FUNCTION;
@@ -931,7 +941,7 @@ call_stmt:
931
941
call->query_tree = NULL ;
932
942
$$ = call;
933
943
}
934
- | CALL expr_func_norm YIELD yield_item_list where_opt
944
+ | CALL expr_func_norm YIELD yield_item_list cypher_where_opt
935
945
{
936
946
cypher_call *call = make_ag_node(cypher_call);
937
947
call->cck = CCK_FUNCTION;
@@ -1409,7 +1419,7 @@ limit_opt:
1409
1419
;
1410
1420
1411
1421
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
1413
1423
{
1414
1424
ListCell *li;
1415
1425
cypher_with *n;
@@ -1443,7 +1453,7 @@ with:
1443
1453
1444
1454
$$ = (Node *)n;
1445
1455
}
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
1447
1457
{
1448
1458
ListCell *li;
1449
1459
cypher_with *n;
@@ -1484,7 +1494,7 @@ with:
1484
1494
*/
1485
1495
1486
1496
match :
1487
- optional_opt MATCH pattern where_opt order_by_opt
1497
+ optional_opt MATCH pattern cypher_where_opt order_by_opt
1488
1498
{
1489
1499
cypher_match *n;
1490
1500
@@ -1895,10 +1905,10 @@ a_expr: c_expr { $$ = $1; }
1895
1905
list_make2($5, $1),
1896
1906
COERCE_SQL_SYNTAX,
1897
1907
@2);
1898
- }
1899
- | '+' a_expr %prec UMINUS
1908
+ }*/
1909
+ | ' +' a_expr // %prec ;
1900
1910
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
1901
- | '-' a_expr %prec UMINUS
1911
+ | '-' a_expr // %prec UMINUS
1902
1912
{ $$ = doNegate($2, @1); }
1903
1913
| a_expr '+' a_expr
1904
1914
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
@@ -1918,16 +1928,16 @@ a_expr: c_expr { $$ = $1; }
1918
1928
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
1919
1929
| a_expr '=' a_expr
1920
1930
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
1921
- | a_expr LESS_EQUALS a_expr
1931
+ /* | a_expr LESS_EQUALS a_expr
1922
1932
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
1923
1933
| a_expr GREATER_EQUALS a_expr
1924
1934
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
1925
1935
| a_expr NOT_EQUALS a_expr
1926
1936
{ $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
1927
1937
1928
- | a_expr qual_Op a_expr %prec Op
1938
+ | a_expr qual_Op a_expr // %prec Op
1929
1939
{ $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
1930
- | qual_Op a_expr %prec Op
1940
+ | qual_Op a_expr // %prec Op
1931
1941
{ $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
1932
1942
1933
1943
| a_expr AND a_expr
@@ -2808,7 +2818,7 @@ merge:
2808
2818
* common
2809
2819
*/
2810
2820
2811
- where_opt :
2821
+ cypher_where_opt :
2812
2822
/* empty */
2813
2823
{
2814
2824
$$ = NULL ;
@@ -4405,4 +4415,43 @@ check_indirection(List *indirection, ag_scanner_t yyscanner)
4405
4415
}
4406
4416
}
4407
4417
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