From: Tom Lane <tgl@sss.pgh.pa.us>
To: jesper@udby.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #13658: DELETE with syntax error in subselect deletes ALL
Date: Thu, 01 Oct 2015 11:52:59 -0400
Message-ID: <17895.1443714779@sss.pgh.pa.us> (raw)
In-Reply-To: <20151001121748.348.81279@wrigleys.postgresql.org>
References: <20151001121748.348.81279@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, jesper@udby.com
Subject: Re: BUG #13658: DELETE with syntax error in subselect deletes ALL
In-Reply-To: <17895.1443714779@sss.pgh.pa.us>
References: <20151001121748.348.81279@wrigleys.postgresql.org> <17895.1443714779@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox