Re: BUG #1784: "adding missing FROM-clause" when not needed

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Giacomo G" <matic999(at)hotmail(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #1784: "adding missing FROM-clause" when not needed
Date: 2005-07-25 14:58:28
Message-ID: 27745.1122303508@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"Giacomo G" <matic999(at)hotmail(dot)com> writes:
> But, when i run the same query with the real name of table in the where
> statement I get this:

> test=# select * from foo t0 join bar t1 on ( t0.a = t1.c ) where foo.a = 1;
> NOTICE: adding missing FROM-clause entry for table "foo"

That is correct --- the statement is not legal per SQL spec, and the
only valid way to interpret it is to treat "foo.a" as a separate
reference to the table. See
http://www.postgresql.org/docs/8.0/static/queries-table-expressions.html#QUERIES-TABLE-ALIASES
or the SELECT reference page, which points out

alias

A substitute name for the FROM item containing the alias. An alias
is used for brevity or to eliminate ambiguity for self-joins (where
the same table is scanned multiple times). When an alias is
provided, it completely hides the actual name of the table or
function; for example given FROM foo AS f, the remainder of the
SELECT must refer to this FROM item as f not foo.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message mohammed talat el shambakey 2005-07-26 11:20:19 BUG #1786: error in establishing connection
Previous Message Richard Huxton 2005-07-25 14:22:41 Re: BUG #1784: "adding missing FROM-clause" when not needed