Skip to content

Commit 28a61fc

Browse files
committed
Remove precedence hacks no longer needed without postfix operators.
It's no longer necessary to assign explicit precedences to GENERATED, NULL_P, PRESERVE, or STRIP_P. Actually, we don't need to assign precedence to IDENT either; that was really just there to govern the behavior of target_el's "a_expr IDENT" production, which no longer ends with that terminal. However, it seems like a good idea to continue to do so, because it provides a reference point for a precedence level that we can assign to other unreserved keywords that lack a natural precedence level. Research by Peter Eisentraut and John Naylor; comment rewrite by me. Discussion: https://postgr.es/m/38ca86db-42ab-9b48-2902-337a0d6b8311@2ndquadrant.com
1 parent 8354e7b commit 28a61fc

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

src/backend/parser/gram.y

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -744,22 +744,15 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
744744
%nonassoc BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
745745
%nonassoc ESCAPE /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
746746
/*
747-
* To support target_el without AS, we must give IDENT an explicit priority
748-
* between ESCAPE and Op. We can safely assign the same priority to
749-
* various unreserved keywords as needed to resolve ambiguities (this can't
750-
* have any bad effects since obviously the keywords will still behave the
751-
* same as if they weren't keywords). We need to do this:
752-
* for PARTITION, RANGE, ROWS, GROUPS to support opt_existing_window_name;
753-
* for RANGE, ROWS, GROUPS so that they can follow a_expr without creating
754-
* postfix-operator problems;
755-
* for GENERATED so that it can follow b_expr;
756-
* and for NULL so that it can follow b_expr in ColQualList without creating
757-
* postfix-operator problems.
747+
* To support target_el without AS, it used to be necessary to assign IDENT an
748+
* explicit precedence just less than Op. While that's not really necessary
749+
* since we removed postfix operators, it's still helpful to do so because
750+
* there are some other unreserved keywords that need precedence assignments.
751+
* If those keywords have the same precedence as IDENT then they clearly act
752+
* the same as non-keywords, reducing the risk of unwanted precedence effects.
758753
*
759-
* To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
760-
* an explicit priority lower than '(', so that a rule with CUBE '(' will shift
761-
* rather than reducing a conflicting rule that takes CUBE as a function name.
762-
* Using the same precedence as IDENT seems right for the reasons given above.
754+
* We need to do this for PARTITION, RANGE, ROWS, and GROUPS to support
755+
* opt_existing_window_name (see comment there).
763756
*
764757
* The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
765758
* are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
@@ -769,9 +762,14 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
769762
* appear to cause UNBOUNDED to be treated differently from other unreserved
770763
* keywords anywhere else in the grammar, but it's definitely risky. We can
771764
* blame any funny behavior of UNBOUNDED on the SQL standard, though.
765+
*
766+
* To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
767+
* an explicit priority lower than '(', so that a rule with CUBE '(' will shift
768+
* rather than reducing a conflicting rule that takes CUBE as a function name.
769+
* Using the same precedence as IDENT seems right for the reasons given above.
772770
*/
773-
%nonassoc UNBOUNDED /* ideally should have same precedence as IDENT */
774-
%nonassoc IDENT GENERATED NULL_P PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
771+
%nonassoc UNBOUNDED /* ideally would have same precedence as IDENT */
772+
%nonassoc IDENT PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
775773
%left Op OPERATOR /* multi-character ops and user-defined operators */
776774
%left '+' '-'
777775
%left '*' '/' '%'
@@ -792,8 +790,6 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
792790
* left-associativity among the JOIN rules themselves.
793791
*/
794792
%left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
795-
/* kluge to keep xml_whitespace_option from causing shift/reduce conflicts */
796-
%right PRESERVE STRIP_P
797793

798794
%%
799795

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy