Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZhgAw-0004N8-6s for pgsql-bugs@arkaria.postgresql.org; Thu, 01 Oct 2015 15:53:42 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZhgAv-0005LQ-Ee for pgsql-bugs@arkaria.postgresql.org; Thu, 01 Oct 2015 15:53:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZhgAJ-0004er-Ga for pgsql-bugs@postgresql.org; Thu, 01 Oct 2015 15:53:03 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZhgAG-0006AG-Vw for pgsql-bugs@postgresql.org; Thu, 01 Oct 2015 15:53:02 +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 t91Fqxb8017896; Thu, 1 Oct 2015 11:52:59 -0400 From: Tom Lane To: jesper@udby.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #13658: DELETE with syntax error in subselect deletes ALL In-reply-to: <20151001121748.348.81279@wrigleys.postgresql.org> References: <20151001121748.348.81279@wrigleys.postgresql.org> Comments: In-reply-to jesper@udby.com message dated "Thu, 01 Oct 2015 12:17:48 -0000" Date: Thu, 01 Oct 2015 11:52:59 -0400 Message-ID: <17895.1443714779@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) 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 jesper@udby.com writes: > -- Failure #1 > DELETE FROM uid_child WHERE parent_uid IN (SELECT parent_uid FROM uid_parent > WHERE id=999); > -- Gives (pgAdmin III): Query returned successfully: 0 rows affected, 21 ms > execution time. > -- psql: DELETE 0 > -- Should fail as there is no "parent_uid" in table uid_parent > -- Failure #2 > DELETE FROM uid_child WHERE parent_uid IN (SELECT parent_uid FROM uid_parent > WHERE id=1); > -- Gives (pgAdmin III): Query returned successfully: 6 rows affected, 11 ms > execution time. > -- psql: DELETE 6 > -- Should fail - and this is rather important, as it actually deletes > everything in uid_child as it is... Unfortunately, this is not a bug, it's just pilot error: parent_uid is a legal outer reference to uid_child's column of that name. This behavior is required by SQL standard. A lot of people make a practice of always table-qualifying names in sub-selects to help protect against this type of thinko. 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