Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id B2FF71337B4E for ; Tue, 22 Feb 2011 14:15:54 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 65640-04 for ; Tue, 22 Feb 2011 18:15:47 +0000 (UTC) X-Greylist: delayed 00:08:04.813143 by SQLgrey-1.7.6 Received: from jalapeno.xigole.com (jalapeno.xigole.com [64.85.162.185]) by mail.postgresql.org (Postfix) with ESMTP id B7B911337B51 for ; Tue, 22 Feb 2011 14:15:46 -0400 (AST) Received: from [192.168.9.193] (unknown [209.117.138.162]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by jalapeno.xigole.com (Postfix) with ESMTPSA id E116A740DA; Tue, 22 Feb 2011 11:07:39 -0700 (MST) Message-ID: <4D63FB6B.3060804@xigole.com> Date: Tue, 22 Feb 2011 11:07:39 -0700 From: Scott Dunbar User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.15pre) Gecko/20110207 Shredder/3.1.9pre MIME-Version: 1.0 To: Tom Lane CC: pgsql-bugs@postgresql.org Subject: Re: BUG #5898: Nested "in" clauses hide bad column names References: <201102221726.p1MHQPDh069580@wwwmaster.postgresql.org> <3314.1298396703@sss.pgh.pa.us> In-Reply-To: <3314.1298396703@sss.pgh.pa.us> Content-Type: multipart/alternative; boundary="------------040104070604080706020305" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.909 tagged_above=-5 required=5 tests=BAYES_00=-1.9, HTML_MESSAGE=0.001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201102/196 X-Sequence-Number: 29468 This is a multi-part message in MIME format. --------------040104070604080706020305 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Yes, you're correct. I guess this makes sense but it does seem strange that I can enter garbage in a query but it still runs. And in my case the output from this (the entire table) was then used in a delete statement that toasted the entire table. Allowing bogus SQL just seems "wrong" but I do understand what's going on. Thanks for your help. On 02/22/2011 10:45 AM, Tom Lane wrote: > "Scott Dunbar" writes: >> I have a nested in clause like: >> select respondent_id from respondent where respondent_id in (select >> respondent_id from chat_session where project_id in (select project_id from >> project where company_id = 4)); >> However, in this example, there is no column named respondent_id in the >> chat_session table. > Probably there is one in respondent, though? This behavior is not a bug > --- what you have there is an outer reference, and it is working exactly > as specified by the SQL standard. Sub-selects would be a whole lot less > useful if they couldn't refer to variables of the outer query. > > regards, tom lane -- Scott Dunbar Xigole Systems, Inc. Enterprise software consulting, development, and hosting 303·667·6343 --------------040104070604080706020305 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Yes, you're correct.  I guess this makes sense but it does seem strange that I can enter garbage in a query but it still runs.  And in my case the output from this (the entire table) was then used in a delete statement that toasted the entire table.  Allowing bogus SQL just seems "wrong" but I do understand what's going on.

Thanks for your help.


On 02/22/2011 10:45 AM, Tom Lane wrote:
"Scott Dunbar" <scott@xigole.com> writes:
I have a nested in clause like:

      
select respondent_id from respondent where respondent_id in (select
respondent_id from chat_session where project_id in (select project_id from
project where company_id = 4));

      
However, in this example, there is no column named respondent_id in the
chat_session table.
Probably there is one in respondent, though?  This behavior is not a bug
--- what you have there is an outer reference, and it is working exactly
as specified by the SQL standard.  Sub-selects would be a whole lot less
useful if they couldn't refer to variables of the outer query.

			regards, tom lane


--
Scott Dunbar
Xigole Systems, Inc.
Enterprise software consulting, development, and hosting
303·667·6343
--------------040104070604080706020305--