Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YvxLa-00072W-Td for pgsql-bugs@arkaria.postgresql.org; Sat, 23 May 2015 00:31:27 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YvxLZ-0004BV-SO for pgsql-bugs@arkaria.postgresql.org; Sat, 23 May 2015 00:31:25 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YvxLX-0004BA-Np for pgsql-bugs@postgresql.org; Sat, 23 May 2015 00:31:23 +0000 Received: from mail-am1on0093.outbound.protection.outlook.com ([157.56.112.93] helo=emea01-am1-obe.outbound.protection.outlook.com) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1YvxLP-0004wN-Ki for pgsql-bugs@postgresql.org; Sat, 23 May 2015 00:31:22 +0000 Received: from AM2PR06MB0690.eurprd06.prod.outlook.com (25.161.19.14) by AM2PR06MB0692.eurprd06.prod.outlook.com (25.161.19.141) with Microsoft SMTP Server (TLS) id 15.1.166.22; Sat, 23 May 2015 00:31:12 +0000 Received: from AM2PR06MB0690.eurprd06.prod.outlook.com ([25.161.19.14]) by AM2PR06MB0690.eurprd06.prod.outlook.com ([25.161.19.14]) with mapi id 15.01.0166.017; Sat, 23 May 2015 00:31:12 +0000 From: Christian Ullrich To: Andres Freund CC: "pgsql-bugs@postgresql.org" Subject: Re: BUG #13336: Unexpected result from invalid query Thread-Topic: [BUGS] BUG #13336: Unexpected result from invalid query Thread-Index: AQHQlO0qUhvzr+eTaEaXhdRrCLONPJ2IsL1Q Date: Sat, 23 May 2015 00:31:10 +0000 Message-ID: References: <20150523000527.17709.45231@wrigleys.postgresql.org> <20150523001227.GA32396@alap3.anarazel.de> In-Reply-To: <20150523001227.GA32396@alap3.anarazel.de> Accept-Language: de-DE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=chris@chrullrich.net; x-originating-ip: [217.31.70.82] x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:AM2PR06MB0692; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(601004)(5005006)(520002)(3002001); SRVR:AM2PR06MB0692; BCL:0; PCL:0; RULEID:; SRVR:AM2PR06MB0692; x-forefront-prvs: 0585417D7B x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(51704005)(199003)(24454002)(189002)(377424004)(54356999)(77156002)(64706001)(19580405001)(74316001)(4001540100001)(106116001)(87936001)(68736005)(2900100001)(46102003)(2950100001)(101416001)(66066001)(106356001)(97736004)(81156007)(50986999)(62966003)(92566002)(76176999)(2656002)(33656002)(122556002)(5001830100001)(5001860100001)(5001920100001)(86362001)(76576001)(15975445007)(5001960100002)(102836002)(189998001)(110136002)(105586002)(19580395003)(40100003); DIR:OUT; SFP:1101; SCL:1; SRVR:AM2PR06MB0692; H:AM2PR06MB0690.eurprd06.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:0; MX:1; LANG:en; received-spf: None (protection.outlook.com: chrullrich.net does not designate permitted sender hosts) Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: chrullrich.net X-MS-Exchange-CrossTenant-originalarrivaltime: 23 May 2015 00:31:10.8710 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 8ee9b5e7-26b6-4fdf-9b47-cf4fbc6d4e3f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM2PR06MB0692 X-Pg-Spam-Score: -3.0 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org * From: Andres Freund [mailto:andres@anarazel.de] > On 2015-05-23 00:05:27 +0000, chris@chrullrich.net wrote: > > -- Note: No column "foo" in test_table2 > > postgres=3D# select * from test_table where foo in (select foo from > > test_table2); > > foo | bar > > -----+----- > > one | 1 > > two | 2 >=20 > That's not a bug. In a good number of subqueries you need access fields > from the surrounding query. Hm. That makes some sense, I guess. But is that true even if the reference = in the subquery is not explicitly qualified? "SELECT foo FROM test_table2" = looks to me like it refers to that table pretty unequivocally. On the other hand I can find one sentence in the documentation on the subje= ct, and it appears to support the conclusion that this is not a bug: http://www.postgresql.org/docs/9.4/static/queries-table-expressions.html: Example: SELECT ... FROM fdt WHERE c1 IN (SELECT c3 FROM t2 WHERE c2 =3D f= dt.c1 + 10) Qualifying c1 as fdt.c1 is only necessary if c1 is also the name of a=20 column in the derived input table of the subquery. That can be read as confirming that resolving the unqualified name against = the outer query is intended. Still seems weird to me. But if that' the way it is, I'm sorry for the nois= e. --=20 Christian --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs