Re: query with table alias

From: Matteo Beccati <php(at)beccati(dot)com>
To: "Rodríguez Rodríguez, Pere" <prr(at)hosppal(dot)es>
Cc: "'pgsql-general(at)postgresql(dot)org'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: query with table alias
Date: 2004-11-12 11:22:00
Message-ID: 41949CD8.5070900@beccati.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


> prr=# select foo.c1, f.c2 from foo f; -- >>> Incorrect result <<<
>
> The result of the "select foo.c1, f.c2 from foo f" isn't correct, it do
> a cartesian product of foo table.

foo is aliased to f, so there's no table named foo in the from clause.
By default postgres tries to add the missing table name, so your query
get rewritten as:

select foo.c1, f.c2 from foo f, foo;

You should also receive a:

NOTICE: adding missing FROM-clause entry for table "foo"

Best regards
--
Matteo Beccati
http://phpadsnew.com
http://phppgads.com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Goutam Paruchuri 2004-11-12 14:06:08 Re: simple query question: return latest
Previous Message Patrick Fiche 2004-11-12 11:13:24 Re: query with table alias