"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