PostgreSQL Bugs

Collected from the PG bugs email list.

Bug ID16520
PG Version12.3
OSdebian:buster-slim
Opened2020-06-30 17:30:33+00
Reported byJesse Lieberg
StatusNew

Body of first available message related to this bug follows.

The following bug has been logged on the website:

Bug reference:      16520
Logged by:          Jesse Lieberg
Email address:      (redacted)
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

Messages

DateAuthorSubject
2020-06-30 17:30:33+00PG Bug reporting formBUG #16520: Deleting from non-existent column in CTE removes all rows
2020-06-30 18:34:05+00Tom LaneRe: BUG #16520: Deleting from non-existent column in CTE removes all rows
2020-06-30 19:01:11+00"David G(dot) Johnston"Re: BUG #16520: Deleting from non-existent column in CTE removes all rows