dbTalk Databases Forums  

[BUGS] BUG #1784: "adding missing FROM-clause" when not needed

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] BUG #1784: "adding missing FROM-clause" when not needed in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Giacomo G
 
Posts: n/a

Default [BUGS] BUG #1784: "adding missing FROM-clause" when not needed - 07-25-2005 , 08:15 AM







The following bug has been logged online:

Bug reference: 1784
Logged by: Giacomo G
Email address: matic999 (AT) hotmail (DOT) com
PostgreSQL version: 8.0.3
Operating system: linux kernel 2.6.12.2
Description: "adding missing FROM-clause" when not needed
Details:

If I populate the database with this two tables:

CREATE TABLE bar ( c varchar, d varchar);
CREATE TABLE foo ( a varchar, b varchar);
COPY bar (c, d) FROM stdin;
1 ghi
2 jkl
\.
COPY foo (a, b) FROM stdin;
1 abc
2 def
\.

When I run this select I get the output I expect:

test=# select * from foo t0 join bar t1 on ( t0.a = t1.c ) where t0.a = 1;
a | b | c | d
---+-----+---+-----
1 | abc | 1 | ghi
(1 row)


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"
a | b | c | d
---+-----+---+-----
1 | abc | 1 | ghi
2 | def | 2 | jkl
(2 rows)

while I expect the same result of the first query.

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Reply With Quote
  #2  
Old   
Michael Fuhr
 
Posts: n/a

Default Re: [BUGS] BUG #1784: "adding missing FROM-clause" when not needed - 07-25-2005 , 09:19 AM






On Mon, Jul 25, 2005 at 03:03:54AM +0100, Giacomo G wrote:
Quote:
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"
See the SELECT documentation:

http://www.postgresql.org/docs/8.0/s...ql-select.html

"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."

If you disable add_missing_from then you'll get an error instead
of a notice and unexpected results. Add_missing_from will be
disabled by default in PostgreSQL 8.1.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend


Reply With Quote
  #3  
Old   
Richard Huxton
 
Posts: n/a

Default Re: [BUGS] BUG #1784: "adding missing FROM-clause" when not needed - 07-25-2005 , 09:26 AM



Giacomo G wrote:
Quote:
But, when i run the same query with the real name of table in the where
statement I get this:
This isn't the "real name" of the table "t0". It is another reference to
table "foo", and as such should either raise an error or arrange to
alter the from-clause to make it valid (which is what happens).

Quote:
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"
a | b | c | d
---+-----+---+-----
1 | abc | 1 | ghi
2 | def | 2 | jkl
(2 rows)

while I expect the same result of the first query.
In recent versions, you can disable the feature in your postgresql.conf
by setting "add_missing_from" to false. See the manuals - run-time
environment / compatibility.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly


Reply With Quote
  #4  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] BUG #1784: "adding missing FROM-clause" when not needed - 07-25-2005 , 09:59 AM



"Giacomo G" <matic999 (AT) hotmail (DOT) com> writes:
Quote:
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/s...-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

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.