Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bdGrH-0007eN-Kn for pgsql-docs@arkaria.postgresql.org; Fri, 26 Aug 2016 13:07:43 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bdGrH-0000rY-7S for pgsql-docs@arkaria.postgresql.org; Fri, 26 Aug 2016 13:07:43 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bdGqv-0000TT-AP for pgsql-docs@postgresql.org; Fri, 26 Aug 2016 13:07:21 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bdGqp-0004zf-O6 for pgsql-docs@postgresql.org; Fri, 26 Aug 2016 13:07:20 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u7QD7EiW026547; Fri, 26 Aug 2016 09:07:14 -0400 From: Tom Lane To: otter117@yahoo.de cc: pgsql-docs@postgresql.org Subject: Re: undocumented feature or bug in subquery : psql (PostgreSQL) 9.4.6 on SLES12 SP1 In-reply-to: <20160825162900.15675.78433@wrigleys.postgresql.org> References: <20160825162900.15675.78433@wrigleys.postgresql.org> Comments: In-reply-to otter117@yahoo.de message dated "Thu, 25 Aug 2016 16:29:00 -0000" Date: Fri, 26 Aug 2016 09:07:14 -0400 Message-ID: <26546.1472216834@sss.pgh.pa.us> X-Pg-Spam-Score: -2.1 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-docs Precedence: bulk Sender: pgsql-docs-owner@postgresql.org otter117@yahoo.de writes: > 2 tables a and b > Table "public.a" > Column | Type | Modifiers > -----------------+--------------------------+--------------- > foo | integer | not null > bar | integer | not null > Table "public.b" > Column | Type | Modifiers > -----------------+--------------------------+--------------- > bar | integer | not null > No error when executing this statement even though table b does not contain > column foo > SELECT foo,bar FROM a WHERE foo=1 AND bar NOT IN (SELECT bar FROM b WHERE > bar > 2 AND foo=2) No, but table a does, and that's a legal outer reference per the SQL standard. This is neither a bug nor undocumented. > Do I need to qualify all columns in the subquery or is this a bug is psql > 9.4.6? It's often wise to qualify column references in multi-table queries (subqueries or not) to ensure they are referencing what you think they're referencing. regards, tom lane -- Sent via pgsql-docs mailing list (pgsql-docs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-docs