pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: jesse007@ymail.com
Subject: BUG #16520: Deleting from non-existent column in CTE removes all rows
Date: Tue, 30 Jun 2020 17:30:33 +0000
Message-ID: <16520-e4e105305f3d0c4a@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      16520
Logged by:          Jesse Lieberg
Email address:      jesse007@ymail.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



view thread (3+ messages)  latest in thread

Message-ID: <16520-e4e105305f3d0c4a@postgresql.org>
Permalink:  ../16520-e4e105305f3d0c4a@postgresql.org/
Also on:    postgresql.org/message-id/16520-e4e105305f3d0c4a@postgresql.org

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, jesse007@ymail.com
  Subject: Re: BUG #16520: Deleting from non-existent column in CTE removes all rows
  In-Reply-To: <16520-e4e105305f3d0c4a@postgresql.org>

* 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