Skip to content

Commit 6fe27ca

Browse files
committed
Fix some operator-precedence problems. New constructs IS DISTINCT FRM
and IS [NOT] OF were not being parsed consistently with other IS forms. Also, make the world a little safer for functions named LEFT, RIGHT, etc.
1 parent e06f4c6 commit 6fe27ca

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/backend/parser/gram.y

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.365 2002/09/02 02:13:01 tgl Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.366 2002/09/05 22:52:48 tgl Exp $
1515
*
1616
* HISTORY
1717
* AUTHOR DATE MAJOR EVENT
@@ -416,7 +416,6 @@ static void doNegateFloat(Value *v);
416416
/* precedence: lowest to highest */
417417
%left UNION EXCEPT
418418
%left INTERSECT
419-
%left JOIN UNIONJOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
420419
%left OR
421420
%left AND
422421
%right NOT
@@ -425,7 +424,7 @@ static void doNegateFloat(Value *v);
425424
%nonassoc LIKE ILIKE SIMILAR
426425
%nonassoc ESCAPE
427426
%nonassoc OVERLAPS
428-
%nonassoc BETWEEN DISTINCT
427+
%nonassoc BETWEEN
429428
%nonassoc IN_P
430429
%left POSTFIXOP /* dummy for postfix Op rules */
431430
%left Op OPERATOR /* multi-character ops and user-defined operators */
@@ -443,6 +442,14 @@ static void doNegateFloat(Value *v);
443442
%left COLLATE
444443
%left TYPECAST
445444
%left '.'
445+
/*
446+
* These might seem to be low-precedence, but actually they are not part
447+
* of the arithmetic hierarchy at all in their use as JOIN operators.
448+
* We make them high-precedence to support their use as function names.
449+
* They wouldn't be given a precedence at all, were it not that we need
450+
* left-associativity among the JOIN rules themselves.
451+
*/
452+
%left JOIN UNIONJOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
446453
%%
447454

448455
/*
@@ -5419,6 +5426,7 @@ r_expr: row IN_P select_with_parens
54195426
$$ = (Node *)makeOverlaps($1, $3);
54205427
}
54215428
| row IS DISTINCT FROM row
5429+
%prec IS
54225430
{
54235431
/* IS DISTINCT FROM has the following rules for non-array types:
54245432
* a) the row lengths must be equal
@@ -5736,13 +5744,13 @@ a_expr: c_expr { $$ = $1; }
57365744
b->booltesttype = IS_NOT_UNKNOWN;
57375745
$$ = (Node *)b;
57385746
}
5739-
| a_expr IS DISTINCT FROM a_expr %prec DISTINCT
5747+
| a_expr IS DISTINCT FROM a_expr %prec IS
57405748
{ $$ = (Node *) makeSimpleA_Expr(DISTINCT, "=", $1, $5); }
5741-
| a_expr IS OF '(' type_list ')'
5749+
| a_expr IS OF '(' type_list ')' %prec IS
57425750
{
57435751
$$ = (Node *) makeSimpleA_Expr(OF, "=", $1, (Node *) $5);
57445752
}
5745-
| a_expr IS NOT OF '(' type_list ')'
5753+
| a_expr IS NOT OF '(' type_list ')' %prec IS
57465754
{
57475755
$$ = (Node *) makeSimpleA_Expr(OF, "!=", $1, (Node *) $6);
57485756
}
@@ -5890,13 +5898,13 @@ b_expr: c_expr
58905898
{ $$ = (Node *) makeA_Expr(OP, $1, NULL, $2); }
58915899
| b_expr qual_Op %prec POSTFIXOP
58925900
{ $$ = (Node *) makeA_Expr(OP, $2, $1, NULL); }
5893-
| b_expr IS DISTINCT FROM b_expr %prec Op
5901+
| b_expr IS DISTINCT FROM b_expr %prec IS
58945902
{ $$ = (Node *) makeSimpleA_Expr(DISTINCT, "=", $1, $5); }
5895-
| b_expr IS OF '(' type_list ')'
5903+
| b_expr IS OF '(' type_list ')' %prec IS
58965904
{
58975905
$$ = (Node *) makeSimpleA_Expr(OF, "=", $1, (Node *) $5);
58985906
}
5899-
| b_expr IS NOT OF '(' type_list ')'
5907+
| b_expr IS NOT OF '(' type_list ')' %prec IS
59005908
{
59015909
$$ = (Node *) makeSimpleA_Expr(OF, "!=", $1, (Node *) $6);
59025910
}

0 commit comments

Comments
 (0)