pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Josh Berkus <josh@agliodbs.com>
Cc: Oleg Lebedev <olebedev@waterford.org>
Cc: pgsql-sql@postgresql.org
Subject: Re: Nested JOINs
Date: Thu, 16 Aug 2001 18:12:31 -0400
Message-ID: <25972.997999951@sss.pgh.pa.us> (raw)
In-Reply-To: <web-103647@davinci.ethosmedia.com>
References: <web-103647@davinci.ethosmedia.com>

"Josh Berkus" <josh@agliodbs.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



view thread (4+ messages)

Message-ID: <25972.997999951@sss.pgh.pa.us>
Permalink:  ../25972.997999951@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/25972.997999951@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, josh@agliodbs.com, olebedev@waterford.org
  Subject: Re: Nested JOINs
  In-Reply-To: <25972.997999951@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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