pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
"<query expression body> ::= <joined table>" grammar rule not accepted by Postgres
3+ messages / 2 participants
[nested] [flat]

* "<query expression body> ::= <joined table>" grammar rule not accepted by Postgres
@ 2011-06-15 21:50 Clem Dickey <dickeycl@us.ibm.com>
  2011-06-16 05:59 ` Re: "<query expression body> ::= <joined table>" grammar rule not accepted by Postgres Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: Clem Dickey @ 2011-06-15 21:50 UTC (permalink / raw)
  To: pgsql-sql


This expression is (I think) a well-formed query, but is rejected by
Postgresql 8.4 (t is a table name).

  t t1 NATURAL JOIN t t2;

Here is the relevant parts of grammar (with some optional elements omitted
for simplicity):

  <query expression> ::= <query expression body>

  <query expression body> ::= <joined table>

  <joined table> ::= <natural join>

  <natural join> ::= <table reference> NATURAL JOIN <table primary>

  <table reference> ::= <table primary>

  <table primary> ::= <table or query name> [ <correlation name> ]

  <table or query name> ::= <table name>

Nor is this use of <joined table> accepted in the <query expression> form
of a <with list element>:

  WITH tw AS ( t t1 NATURAL JOIN t t2 ) TABLE tw;

This leads me to believe that the unrecognized grammar rule (in SQL99
standard terms) is

 <query expression body> ::= <joined table>

There are, of course, other ways to express the operation, including
  SELECT * FROM (t t1 NATURAL JOIN t t2);
But I am curious why the first expression is not accepted, besides the
immediately obvious "it's not in the Postgres version of the SQL grammar."

Clem Dickey

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: "<query expression body> ::= <joined table>" grammar rule not accepted by Postgres
  2011-06-15 21:50 "<query expression body> ::= <joined table>" grammar rule not accepted by Postgres Clem Dickey <dickeycl@us.ibm.com>
@ 2011-06-16 05:59 ` Tom Lane <tgl@sss.pgh.pa.us>
  2011-06-16 19:07   ` Re: "<query expression body> ::= <joined table>" grammar rule not accepted by Postgres Clem Dickey <dickeycl@us.ibm.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2011-06-16 05:59 UTC (permalink / raw)
  To: Clem Dickey <dickeycl@us.ibm.com>; +Cc: pgsql-sql

Clem Dickey <dickeycl@us.ibm.com> writes:
> This expression is (I think) a well-formed query, but is rejected by
> Postgresql 8.4 (t is a table name).

>   t t1 NATURAL JOIN t t2;

Hmm ... I think you are looking at SQL92 or SQL99.  The later versions
of the spec don't seem to permit <joined table> to be used that way.
In particular, in SQL:2003 and SQL:2007 I don't see any derivation path
from <query expression> to <joined table>.  So while we possibly could
support this, it's legacy syntax, and I doubt there's enough interest to
bother.

[ digs a bit more... ]  Ah, here we are: Annex E of SQL:2003 calls out
various incompatibilities from SQL:99, notably

	6) In ISO/IEC 9075-2:1999, a <query expression body>, <query
	term>, or <query primary> could consist of a <joined
	table>. None of those three elements can consist of a <joined
	table> in this edition of ISO/IEC 9075.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: "<query expression body> ::= <joined table>" grammar rule not accepted by Postgres
  2011-06-15 21:50 "<query expression body> ::= <joined table>" grammar rule not accepted by Postgres Clem Dickey <dickeycl@us.ibm.com>
  2011-06-16 05:59 ` Re: "<query expression body> ::= <joined table>" grammar rule not accepted by Postgres Tom Lane <tgl@sss.pgh.pa.us>
@ 2011-06-16 19:07   ` Clem Dickey <dickeycl@us.ibm.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Clem Dickey @ 2011-06-16 19:07 UTC (permalink / raw)
  To: pgsql-sql

On 06/15/2011 10:59 PM, Tom Lane wrote:
> Clem Dickey<dickeycl@us.ibm.com>  writes:
>> This expression is (I think) a well-formed query, but is rejected by
>> Postgresql 8.4 (t is a table name).
>
>>    t t1 NATURAL JOIN t t2;
>
> Hmm ... I think you are looking at SQL92 or SQL99.

> [ digs a bit more... ]  Ah, here we are: Annex E of SQL:2003 calls out
> various incompatibilities from SQL:99, notably
>
> 	6) In ISO/IEC 9075-2:1999, a<query expression body>,<query
> 	term>, or<query primary>  could consist of a<joined
> 	table>. None of those three elements can consist of a<joined
> 	table>  in this edition of ISO/IEC 9075.

Thanks for the research. I was indeed reading from SQL99, which was 
current the last time I used SQL. I'll have to spring for a newer 
standard (or the equivalent).



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2011-06-16 19:07 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-06-15 21:50 "<query expression body> ::= <joined table>" grammar rule not accepted by Postgres Clem Dickey <dickeycl@us.ibm.com>
2011-06-16 05:59 ` Tom Lane <tgl@sss.pgh.pa.us>
2011-06-16 19:07   ` Clem Dickey <dickeycl@us.ibm.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox