Re: BUG #1784: "adding missing FROM-clause" when not needed - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #1784: "adding missing FROM-clause" when not needed
Date
Msg-id 27745.1122303508@sss.pgh.pa.us
Whole thread Raw
In response to BUG #1784: "adding missing FROM-clause" when not needed  ("Giacomo G" <matic999@hotmail.com>)
List pgsql-bugs
"Giacomo G" <matic999@hotmail.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

pgsql-bugs by date:

Previous
From: Richard Huxton
Date:
Subject: Re: BUG #1784: "adding missing FROM-clause" when not needed
Next
From: pod@herald.ox.ac.uk (pod)
Date:
Subject: krb5 authentication and multihomed server hosts