Re: Gram.y patches for better parenthesis handling. - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Gram.y patches for better parenthesis handling.
Date
Msg-id 6784.972708940@sss.pgh.pa.us
Whole thread Raw
In response to Gram.y patches for better parenthesis handling.  ("Kevin O'Gorman" <kogorman@pacbell.net>)
List pgsql-hackers
"Kevin O'Gorman" <kogorman@pacbell.net> writes:
> 2) It does NOT preserve the odd syntax I found when I started looking
> at this, where a SELECT statement could begin with parentheses.  Thus,
>   (SELECT a from foo) order by a;
> fails.

Um, as a general rule that's not an acceptable limitation.  Consider
(SELECT foo EXCEPT SELECT bar) INTERSECT SELECT baz;

Without parens this will mean something quite different, since
INTERSECT has higher precedence than EXCEPT.

Also, a leading paren is clearly legal according to SQL92 --- trace
for example the productions        <direct select statement: multiple rows>        <query expression>        <non-join
queryexpression>        <non-join query term>        <non-join query primary> ::=             <left paren> <non-join
queryexpression> <right paren>
 

(UNION/EXCEPT structures are <non-join query expression> in this
hierarchy.)

The reason that making this grammar yacc-compatible is so hard is
precisely that leading parens must sometimes be part of the SELECT
structure, whereas extraneous parens need to be kept out of it.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Re: [GENERAL] A rare error
Next
From: Tom Lane
Date:
Subject: Re: Can't import date using copy