dbTalk Databases Forums  

Re: [BUGS] BUG #1540: Enhancement request: 'ambiguous' column reference

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


Discuss Re: [BUGS] BUG #1540: Enhancement request: 'ambiguous' column reference in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Neil Conway
 
Posts: n/a

Default Re: [BUGS] BUG #1540: Enhancement request: 'ambiguous' column reference - 03-13-2005 , 09:03 PM






Richard Neill wrote:
Quote:
I think that the first query ought to succeed, since although priceband is
ambiguous (it could mean either tbl_prices.priceband or
tbl_instruments.priceband), the information in the WHERE clause means that
they are explicitly equal, and so it doesn't matter which one we use.
Well, it just means the type's equality operator returns true for these
two values -- I'm not sure it is wise to assume they are completely
interchangeable.

More generally, it makes sense to me that resolution of column
references is a property of the syntax of a statement, not something
derived from its semantics (e.g. the fact that we can infer for some
particular statement that two columns are equal).

-Neil

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings


Reply With Quote
  #2  
Old   
Richard Neill
 
Posts: n/a

Default Re: [BUGS] BUG #1540: Enhancement request: 'ambiguous' column reference - 03-17-2005 , 11:22 PM






Dear Tom and Neil,

Thanks very much for your help, and your explanations. This makes a lot
of sense, and I agree - this bug is definitely invalid.

Best wishes

Richard




Tom Lane wrote:
Quote:
"Richard Neill" <postgresql (AT) richardneill (DOT) org> writes:

SELECT instrument,priceband,pounds FROM tbl_instruments,tbl_prices WHERE
tbl_instruments.priceband=tbl_prices.priceband;


ERROR: column reference "priceband" is ambiguous


I think that the first query ought to succeed, since although priceband is
ambiguous (it could mean either tbl_prices.priceband or
tbl_instruments.priceband), the information in the WHERE clause means that
they are explicitly equal, and so it doesn't matter which one we use.


Doing that would be contrary to the SQL specification, AFAICS.

However, you can get the effect you want by writing the query like

SELECT instrument,priceband,pounds FROM
tbl_instruments JOIN tbl_prices USING (priceband);

which both provides the join condition and logically merges the two
input columns into just one output column.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: 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.