"<query expression body> ::= <joined table>" grammar rule not accepted by Postgres
"<query expression body> ::= <joined table>" grammar rule not accepted by Postgres
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
Re: "<query expression body> ::= <joined table>" grammar rule not accepted by Postgres
Clem Dickey 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 to be used that way. In particular, in SQL:2003 and SQL:2007 I don't see any derivation path from to . 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 , , or could consist of a . None of those three elements can consist of a in this edition of ISO/IEC 9075. regards, tom lane
Re: "<query expression body> ::= <joined table>" grammar rule not accepted by Postgres
On 06/15/2011 10:59 PM, Tom Lane wrote: > Clem Dickey 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, term>, or could consist of a table>. None of those three elements can consist of a 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).