From: Bruce Momjian <maillist@candle.pha.pa.us>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Howie <caffeine@toodarkpark.org>
Cc: pgsql-sql@hub.org
Subject: Re: [SQL] table aliasing problem with 6.5...
Date: Mon, 27 Sep 1999 13:44:19 -0400 (EDT)
Message-ID: <199909271744.NAA09308@candle.pha.pa.us> (raw)
In-Reply-To: <11578.934034693@sss.pgh.pa.us>
> Howie <caffeine@toodarkpark.org> writes:
> > (1) why is it trying to do a cartesian join when not using the aliased
> > tables?
>
> That's what it's supposed to do. When you provide an alias for a table
> name in FROM, then as far as the rest of that query is concerned, that
> alias *is* the name of the table --- it has no other. When you refer
> to the original table name in the WHERE clause, that's taken as creating
> a separate table reference that's implicitly added to FROM. Your query
> is a four-way join with only one join having a restriction clause :-(
>
> The alias behavior is necessary in order to handle self-joins properly,
> for example to find married couples:
> SELECT * FROM person, person other WHERE person.spouse = other.spouse;
> This would be ambiguous if "person" were exposed by the second FROM clause.
> SQL92 requires it to work this way:
>
> <table reference> ::=
> <table name> [ [ AS ] <correlation name>
> [ <left paren> <derived column list> <right paren> ] ]
>
> ...
>
> 1) A <correlation name> immediately contained in a <table refer-
> ence> TR is exposed by TR. A <table name> immediately contained
> in a <table reference> TR is exposed by TR if and only if TR
> does not specify a <correlation name>.
>
>
> I think that implicitly adding a table to FROM is a Postgres extension
> not found in SQL92 --- we probably really ought to reject such a query
> with an error, since this behavior seems to be surprising...
OK, I have added an elog(NOTICE) for this behavior:
test=> select * from pg_language;
lanname |lanispl|lanpltrusted|lanplcallfoid|lancompiler
--------+-------+------------+-------------+--------------
internal|f |f | 0|n/a
lisp |f |f | 0|/usr/ucb/liszt
C |f |f | 0|/bin/cc
sql |f |f | 0|postgres
(4 rows)
test=> select pg_language.*;
--> NOTICE: Auto-creating query reference to table pg_language
lanname |lanispl|lanpltrusted|lanplcallfoid|lancompiler
--------+-------+------------+-------------+--------------
internal|f |f | 0|n/a
lisp |f |f | 0|/usr/ucb/liszt
C |f |f | 0|/bin/cc
sql |f |f | 0|postgres
(4 rows)
I am interested in comments about my wording, and this behavour.
--
Bruce Momjian | http://www.op.net/~candle
maillist@candle.pha.pa.us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: maillist@candle.pha.pa.us, tgl@sss.pgh.pa.us, caffeine@toodarkpark.org, pgsql-sql@hub.org
Subject: Re: [SQL] table aliasing problem with 6.5...
In-Reply-To: <199909271744.NAA09308@candle.pha.pa.us>
References: <11578.934034693@sss.pgh.pa.us> <199909271744.NAA09308@candle.pha.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