Re: Binding of "AS" vis "JOIN"

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Karl O(dot) Pinc" <kop(at)meme(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Binding of "AS" vis "JOIN"
Date: 2005-02-04 18:15:03
Message-ID: 15911.1107540903@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Karl O. Pinc" <kop(at)meme(dot)com> writes:
> I'm doing some complicated joining and am getting error
> messages about unknown relations and can't figure out
> what's up. I'm wondering if "as" aliasing gives
> an alias to the product of a join, not just the
> one table that appears immediately in front of the
> "as". ?

If you write

... FROM (a JOIN b) AS c

then (1) the alias c refers to the whole join result, not either a or b
and (2) you can't directly reference the table aliases a or b from
outside this JOIN clause: the alias c masks them. This behavior is per
SQL spec.

> The other question that sprang to mind while working
> on this was whether there's performance (or any other)
> implications of using WHERE conditions instead of
> JOIN inside FROM.

See
http://www.postgresql.org/docs/8.0/static/explicit-joins.html
(adjust URL to match the major version you are running, as the answers
vary).

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Juan Casero (FL FLC) 2005-02-04 18:22:43 Re: plpgsql function errors
Previous Message Martijn van Oosterhout 2005-02-04 18:06:18 Re: plpgsql function errors