Skip site navigation (1) Skip section navigation (2)

Re: A rare error

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: DaVinci <bombadil(at)wanadoo(dot)es>
Cc: Lista PostgreSql <pgsql-general(at)postgresql(dot)org>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: A rare error
Date: 2000-10-25 16:28:35
Message-ID: 28782.972491315@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-hackers
DaVinci <bombadil(at)wanadoo(dot)es> writes:
> An extrange behavior with PostgreSql 7.0.2:
> 	select * from foo where exists
> 	(select * from foo)
> works fine. But:
> 	select * from foo where exists
> 	((select * from foo))
> shows an error:
> 	ERROR: parser: parse error at or near "("
> Is this a bug?

I was fooling around with exactly that point a couple weeks ago.  You'd
think it would be easy to allow extra parentheses around a sub-select,
but I couldn't figure out any way to do it that didn't provoke shift/
reduce conflicts or worse.

The main problem is that if parentheses are both part of the expression
grammar (as they'd better be ;-)) and part of the SELECT grammar then
for a construct like
	select (((select count(foo) from bar)));
it's ambiguous whether the extra parens are expression parens or part
of the inner SELECT statement.  You may not care, but yacc does: it does
not like ambiguous grammars.  AFAICS the only solution is not to allow
parentheses at the very top level of a SELECT structure.  Then the above
is not ambiguous because all the extra parens are expression parens.

This solution leads directly to your complaint: the syntax is
	EXISTS ( SELECT ... )
and you don't get to insert any unnecessary levels of parenthesis.

We could maybe hack something for EXISTS in particular (since we know
a parenthesized SELECT must follow it) but in the general case there
doesn't seem to be a way to make it work.  For example, in current
sources this is OK:
	select * from foo where exists
	((select * from foo) union (select * from bar));
but not this:
	select * from foo where exists
	((select * from foo) union ((select * from bar)));
	ERROR:  parser: parse error at or near ")"

If there are any yacc hackers out there who think they can improve on
this, please grab gram.y from current CVS and have at it.  It'd be nice
not to have an artificial restriction against redundant parentheses in
SELECT structures.

			regards, tom lane

In response to

pgsql-hackers by date

Next:From: Tom LaneDate: 2000-10-25 16:49:08
Subject: Re: length coerce for bpchar is broken since 7.0
Previous:From: Bruce GuenterDate: 2000-10-25 16:27:15
Subject: Re: [Fwd: [CORE SDI ADVISORY] MySQL weak authentication]

pgsql-general by date

Next:From: Tom LaneDate: 2000-10-25 16:36:19
Subject: Re: Looking for help with using regular expression match or perl language functions
Previous:From: Stephan SzaboDate: 2000-10-25 16:01:03
Subject: Re: A rare error

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group