Re: Subselect with incorrect column not a syntax error?

From: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>
To: Jack Christensen <jackc(at)hylesanderson(dot)edu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Subselect with incorrect column not a syntax error?
Date: 2012-04-13 18:34:47
Message-ID: CAOR=d=3dRXAHxhvHh6-VYJb9a0r6redL1s13GzJuiNAX+q28aA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Apr 13, 2012 at 11:59 AM, Jack Christensen
<jackc(at)hylesanderson(dot)edu> wrote:
> On 4/13/2012 11:39 AM, Mike Blackwell wrote:
>>
>> Could someone please explain to me why the following select does not
>> result in a syntax error?  (9.0.3)
>>
>> begin;
>>
>> create table x( c1 integer , c2 integer);
>> create table y( c3 integer, c4 integer);
>>
>> select * from x where c2 in ( select c2 from y where c4 = 2 );
>>
>>
>> rollback;
>>
>> Mike
>>
> Your subquery is correlated with the outer query. So the c2 in the subquery
> is referring to table x.

This is a good example of why one should always use a table alias
prefix when using subqueries.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2012-04-13 18:35:47 Re: Value to long for type ....: Columnname missing
Previous Message Guillaume Lelarge 2012-04-13 18:32:04 Re: Value to long for type ....: Columnname missing