Unix Technical Forum

Bug about column references within subqueries used in selects

This is a discussion on Bug about column references within subqueries used in selects within the pgsql Hackers forums, part of the PostgreSQL category; --> Hi, Shouldn't the final command below cause a 'column "b" does not exist error'? create table update_test (a int, ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Hackers

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-12-2008, 08:16 AM
NikhilS
 
Posts: n/a
Default Bug about column references within subqueries used in selects

Hi,

Shouldn't the final command below cause a 'column "b" does not exist error'?

create table update_test (a int, b int);
create table supdate_test(x int, y int);
insert into update_test values (20, 30);
insert into supdate_test values (40, 50);
select a, (select b from supdate_test) from update_test;

a ?column?
---------- -------------------------
20 30

Is the problem with the code in colNameToVar or maybe we should add checks
in transformSubLink?

Regards,
Nikhils
--
EnterpriseDB http://www.enterprisedb.com

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-12-2008, 08:16 AM
Merlin Moncure
 
Posts: n/a
Default Re: Bug about column references within subqueries used in selects

On 4/12/07, NikhilS <nikkhils@gmail.com> wrote:
> Hi,
>
> Shouldn't the final command below cause a 'column "b" does not exist error'?
>
> create table update_test (a int, b int);
> create table supdate_test(x int, y int);
> insert into update_test values (20, 30);
> insert into supdate_test values (40, 50);
> select a, (select b from supdate_test) from update_test;
>
> a ?column?
> ---------- -------------------------
> 20 30
>
> Is the problem with the code in colNameToVar or maybe we should add checks
> in transformSubLink?


I don't think so...the columns of update_test are visible to the
scalar subquery...that way you can use fields from 'a' to filter the
subquery...
select a, (select y from supdate_test where x = a) from update_test;

merlin

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-12-2008, 08:16 AM
NikhilS
 
Posts: n/a
Default Re: Bug about column references within subqueries used in selects

Hi,

On 4/12/07, Merlin Moncure <mmoncure@gmail.com> wrote:
>
> On 4/12/07, NikhilS <nikkhils@gmail.com> wrote:
> > Hi,
> >
> > Shouldn't the final command below cause a 'column "b" does not exist

> error'?
> >
> > create table update_test (a int, b int);
> > create table supdate_test(x int, y int);
> > insert into update_test values (20, 30);
> > insert into supdate_test values (40, 50);
> > select a, (select b from supdate_test) from update_test;
> >
> > a ?column?
> > ---------- -------------------------
> > 20 30
> >
> > Is the problem with the code in colNameToVar or maybe we should add

> checks
> > in transformSubLink?

>
> I don't think so...the columns of update_test are visible to the
> scalar subquery...that way you can use fields from 'a' to filter the
> subquery...
> select a, (select y from supdate_test where x = a) from update_test;



Yes this is fine, but in "select columnname from tablename" using column
references of the other involved table is what I am objecting to.

Regards,
Nikhils


--
EnterpriseDB http://www.enterprisedb.com

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-12-2008, 08:16 AM
Bort, Paul
 
Posts: n/a
Default Re: Bug about column references within subqueries used in selects

>
> I don't think so...the columns of update_test are visible to the
> scalar subquery...that way you can use fields from 'a'
> to filter the
> subquery...
> select a, (select y from supdate_test where x = a) from
> update_test;
>
>
> Yes this is fine, but in "select columnname from tablename"
> using column references of the other involved table is what I
> am objecting to.
>


There's nothing here to object to, the system is acting correctly. Your
column name "b" is ambiguous, and the system takes the column "b" that
exists, rather than returning an error on a column that doesn't exist.
If you were explicit in your column name, you would get an error:

=# select a, (select supdate_test.b from supdate_test) from update_test;
ERROR: No such attribute supdate_test.b

Regards,
Paul

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-12-2008, 08:16 AM
Tom Lane
 
Posts: n/a
Default Re: Bug about column references within subqueries used in selects

NikhilS <nikkhils@gmail.com> writes:
> Yes this is fine, but in "select columnname from tablename" using column
> references of the other involved table is what I am objecting to.


You can object till you're blue in the face, but this behavior is not
changing because it's *required by spec*. Outer references are a
standard and indeed essential part of SQL.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:06 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com