Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Zhfo5-0003Ha-HE for pgsql-bugs@arkaria.postgresql.org; Thu, 01 Oct 2015 15:30:05 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1Zhfo5-0002kL-18 for pgsql-bugs@arkaria.postgresql.org; Thu, 01 Oct 2015 15:30:05 +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 1ZhcoM-0001Dc-VL for pgsql-bugs@postgresql.org; Thu, 01 Oct 2015 12:18:11 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1ZhcoH-0001Sb-Nt for pgsql-bugs@postgresql.org; Thu, 01 Oct 2015 12:18:10 +0000 MIME-Version: 1.0 Subject: BUG #13658: DELETE with syntax error in subselect deletes ALL To: pgsql-bugs@postgresql.org From: jesper@udby.com Date: Thu, 01 Oct 2015 12:17:48 +0000 Message-ID: <20151001121748.348.81279@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.9 (-) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 The following bug has been logged on the website: Bug reference: 13658 Logged by: Jesper Udby Email address: jesper@udby.com PostgreSQL version: 9.3.9 Operating system: Ubuntu 14.04 LTS Description: The following SQL illustrates an error in the SQL parser. There is a syntax error in the subselect for the DELETE statements below, but the DELETE succeeds, and either deletes nothing or EVERYTHING in the referenced table: -- -- SETUP -- CREATE TABLE uid_parent ( id integer NOT NULL, uid character varying(32) NOT NULL, name text NOT NULL, CONSTRAINT uid_parent_pkey PRIMARY KEY (id), CONSTRAINT uid_parent_uid_key UNIQUE (uid) ); CREATE TABLE uid_child ( id serial NOT NULL, uid character varying(32) NOT NULL, parent_uid character varying(32) NOT NULL, name text NOT NULL, CONSTRAINT uid_child_pkey PRIMARY KEY (id), CONSTRAINT uid_child_uid_key UNIQUE (uid) ); -- TEST-DATA INSERT INTO uid_parent(id, uid, name) VALUES (1, 'bb9515ebbe724f0d9e0b4fc2d72a59b6', 'parent 1'); INSERT INTO uid_parent(id, uid, name) VALUES (2, 'c4d48e735c02450bbea9731e8cf9b749', 'parent 2'); INSERT INTO uid_parent(id, uid, name) VALUES (3, '4b0cf89e9f66463bb52df13f6bf477eb', 'parent 3'); INSERT INTO uid_parent(id, uid, name) VALUES (4, '266043aced6546aba96126d9afad2f24', 'parent 4'); INSERT INTO uid_child(uid, parent_uid, name) VALUES ('6337a55732184bb9b58e687e1ebccbd5', 'bb9515ebbe724f0d9e0b4fc2d72a59b6', 'child 1.1'); INSERT INTO uid_child(uid, parent_uid, name) VALUES ('19463cf1f0e049bc84b6991ec940cd9f', 'bb9515ebbe724f0d9e0b4fc2d72a59b6', 'child 1.2'); INSERT INTO uid_child(uid, parent_uid, name) VALUES ('e54c9a867f374b1889031c2fd06d8ea9', 'bb9515ebbe724f0d9e0b4fc2d72a59b6', 'child 1.3'); INSERT INTO uid_child(uid, parent_uid, name) VALUES ('0a4df934c57446b995a391ac62664633', 'c4d48e735c02450bbea9731e8cf9b749', 'child 2.1'); INSERT INTO uid_child(uid, parent_uid, name) VALUES ('2e441dfe655f48b1b9ea5faabc9707d4', 'c4d48e735c02450bbea9731e8cf9b749', 'child 2.2'); INSERT INTO uid_child(uid, parent_uid, name) VALUES ('5e7bba4b1d134e0faf40b5e45eb093c4', '4b0cf89e9f66463bb52df13f6bf477eb', 'child 3.1'); -- 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... -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs