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 1pHgxE-00040Y-16 for pgsql-bugs@arkaria.postgresql.org; Tue, 17 Jan 2023 08:04:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pHgxC-0007qe-JV for pgsql-bugs@arkaria.postgresql.org; Tue, 17 Jan 2023 08:04:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pHgxC-0007qV-Ah for pgsql-bugs@lists.postgresql.org; Tue, 17 Jan 2023 08:04:22 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pHgxA-0001K0-58 for pgsql-bugs@lists.postgresql.org; Tue, 17 Jan 2023 08:04:21 +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 30H84ISZ2915687; Tue, 17 Jan 2023 03:04:18 -0500 From: Tom Lane To: "=?ISO-8859-1?B?WGlvbmcgSGU=?=" cc: "=?ISO-8859-1?B?cGdzcWwtYnVncw==?=" Subject: Re: Possible wrong result with some "in" subquery with non-existing columns In-reply-to: References: Comments: In-reply-to "=?ISO-8859-1?B?WGlvbmcgSGU=?=" message dated "Tue, 17 Jan 2023 08:00:09 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2915685.1673942658.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 17 Jan 2023 03:04:18 -0500 Message-ID: <2915686.1673942658@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "=3D?ISO-8859-1?B?WGlvbmcgSGU=3D?=3D" writes: > mydb=3D# create table test1(id1 int primary key, col2 varchar(32)); > mydb=3D# create table test2(id2 int primary key, col2 varchar(32)); > mydb=3D# select * from test1 where id1 in (select id1 from test2 where i= d2 =3D 2); > In the above query: id1 is not a column of table test2. Nope, but it's a legal outer reference. > Should not we expect this should be en error instead of it thinking it's= a column from the table : test1? = This behavior is required by the SQL standard, and has been for decades. Yes, it trips up novices all the time, but it does have valid use-cases. regards, tom lane