Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pIaoL-0008UA-SB for pgsql-bugs@arkaria.postgresql.org; Thu, 19 Jan 2023 19:42:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pIaoK-0005ZR-NJ for pgsql-bugs@arkaria.postgresql.org; Thu, 19 Jan 2023 19:42:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pIaoK-0005Yx-FF for pgsql-bugs@lists.postgresql.org; Thu, 19 Jan 2023 19:42:56 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pIaoD-0006ft-SW for pgsql-bugs@lists.postgresql.org; Thu, 19 Jan 2023 19:42:55 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 30JJgmCC4191912; Thu, 19 Jan 2023 14:42:48 -0500 From: Tom Lane To: gurmokh.sangha@starlingbank.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17754: Subquery IN clause returns row matches where subquery is invalid In-reply-to: <17754-0c04a53e0078e5d6@postgresql.org> References: <17754-0c04a53e0078e5d6@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Thu, 19 Jan 2023 18:02:11 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4191910.1674157368.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 19 Jan 2023 14:42:48 -0500 Message-ID: <4191911.1674157368@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > A subquery that has an incorrect column name, that happens to match a co= lumn > name in the outer query evaluates as true for all rows in the outer quer= y. Such a reference is called an "outer reference", and it's a required feature in the SQL standard. The reason you get "true" is that the expression > where a in ( select a from btable where c =3D 10) ; is basically reducing to "a =3D a". https://wiki.postgresql.org/wiki/FAQ#Why_doesn.27t_PostgreSQL_report_a_col= umn_not_found_error_when_using_the_wrong_name_in_a_subquery.3F regards, tom lane