Re: Nested JOINs

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Josh Berkus" <josh(at)agliodbs(dot)com>
Cc: Oleg Lebedev <olebedev(at)waterford(dot)org>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Nested JOINs
Date: 2001-08-16 22:12:31
Message-ID: 25972.997999951@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Josh Berkus" <josh(at)agliodbs(dot)com> writes:
> Second, you can't alias a JOINed set of tables;

Actually you can, according to my reading of SQL92:

<table reference> ::=
<table name> [ [ AS ] <correlation name>
[ <left paren> <derived column list> <right paren> ] ]
| <derived table> [ AS ] <correlation name>
[ <left paren> <derived column list> <right paren> ]
| <joined table>

<derived table> ::= <table subquery>

<table subquery> ::= <subquery>

<subquery> ::= <left paren> <query expression> <right paren>

<query expression> ::=
<non-join query expression>
| <joined table>

<joined table> ::=
<cross join>
| <qualified join>
| <left paren> <joined table> <right paren>

<qualified join> ::=
<table reference> [ NATURAL ] [ <join type> ] JOIN
<table reference> [ <join specification> ]

So a parenthesized <qualified join> is a <derived table> and may
be followed by [ AS ] <correlation name>.

7.1 gets this right. 7.0's very preliminary implementation of JOIN
syntax did not. (It had a number of other bugs too, IIRC.)

The spec's grammar is horribly badly written: it's ambiguous whether the
parentheses should be parsed as part of a second-level <joined table>
which would imply that a correlation name would NOT be accepted.
It took a fair amount of work to derive a grammar that was unambiguous
and still accepted everything...

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Horst Herb 2001-08-16 22:24:51 Fwd: [SQL] how to use record type
Previous Message Peter Eisentraut 2001-08-16 22:05:40 Re: Interval FAQ - please review