Re: BUG #16520: Deleting from non-existent column in CTE removes all rows

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: "jesse007(at)ymail(dot)com" <jesse007(at)ymail(dot)com>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #16520: Deleting from non-existent column in CTE removes all rows
Date: 2020-06-30 19:01:11
Message-ID: CAKFQuwbY5dPkv1GNsuxyoPpCYPrao=W0P5NnQ==wBq7vMR-KEQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tuesday, June 30, 2020, PG Bug reporting form <noreply(at)postgresql(dot)org>
wrote:

> The following bug has been logged on the website:
>
> Bug reference: 16520
> Logged by: Jesse Lieberg
> Email address: jesse007(at)ymail(dot)com
> PostgreSQL version: 12.3
> Operating system: debian:buster-slim
> Description:
>
> However, the this will not return an error and instead deletes all rows:
> ```
> WITH to_delete AS (
> SELECT MIN(id), username
> FROM test
> GROUP BY username
> HAVING count(*) > 1
> )
> DELETE FROM test
> WHERE id IN (
> SELECT id
> FROM to_delete
> );
>

Yes, because the column id does exist - you just omitted the table
reference which ends up making the subquery query equivalent to: “select
test.id from to_delete” which is mandatory, and generally useful, sql
syntax.

David J.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Jehan-Guillaume de Rorthais 2020-06-30 19:47:26 Re: [BUG][PATCH] ecpg crash with bytea type and cursors
Previous Message Michael Meskes 2020-06-30 18:47:11 Re: [BUG][PATCH] ecpg crash with bytea type and cursors