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

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: jesse007(at)ymail(dot)com
Subject: BUG #16520: Deleting from non-existent column in CTE removes all rows
Date: 2020-06-30 17:30:33
Message-ID: 16520-e4e105305f3d0c4a@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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:

Using the `postgres:12` docker image and given the following:
```
DROP TABLE IF EXISTS test;
CREATE TABLE test (
id SERIAL,
username varchar(32)
);
INSERT INTO test (username)
VALUES ('Jesse'), ('Jesse'), ('Scott'), ('Scott'), ('John');
```

This will throw an error that the column does not exist:
```
WITH to_delete AS (
SELECT MIN(id), username
FROM test
GROUP BY username
HAVING count(*) > 1
)
SELECT id
FROM to_delete;
```

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
);
```

More information: https://stackoverflow.com/q/62661721/3903479

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2020-06-30 17:50:18 Re: BUG #16519: SET SESSION ROLE in plpgsql requires string literal.
Previous Message Tom Lane 2020-06-30 17:19:56 Re: [BUG][PATCH] ecpg crash with bytea type and cursors