Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W7yBd-0007pd-Cl for pgsql-bugs@arkaria.postgresql.org; Tue, 28 Jan 2014 02:14:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1W7yBc-0004tS-Of for pgsql-bugs@arkaria.postgresql.org; Tue, 28 Jan 2014 02:14:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W7yBT-0004qx-2M for pgsql-bugs@postgresql.org; Tue, 28 Jan 2014 02:13:51 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W7yBM-0000pa-OJ for pgsql-bugs@postgresql.org; Tue, 28 Jan 2014 02:13:50 +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 s0S2DhPI000427; Mon, 27 Jan 2014 21:13:43 -0500 From: Tom Lane To: martin.nzioki@gmail.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #9006: Incorrect update when using where with non-existent column in subselect In-reply-to: <20140128000840.26702.60938@wrigleys.postgresql.org> References: <20140128000840.26702.60938@wrigleys.postgresql.org> Comments: In-reply-to martin.nzioki@gmail.com message dated "Tue, 28 Jan 2014 00:08:40 +0000" Date: Mon, 27 Jan 2014 21:13:43 -0500 Message-ID: <420.1390875223@sss.pgh.pa.us> X-Pg-Spam-Score: -2.4 (--) 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 martin.nzioki@gmail.com writes: > create table _test1 (id int not null primary key, c2 int); > insert into _test1 (id) select * from generate_series(1, 5); > create table _tmp_test2 (id_fk int not null); > insert into _tmp_test2 (id_fk) select id from _test1 limit 2; > update _test1 set c2 = 7 where id in (select id from _tmp_test2); This is a FAQ ... that statement is perfectly valid per SQL standard, it just doesn't do what you expect, because the sub-select's "id" is taken as an outer reference to _test1's id column. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs