subquery column error causes data destroying equality

From: Cy <frompostgres(at)cy1(dot)allowed(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: subquery column error causes data destroying equality
Date: 2020-07-25 03:23:34
Message-ID: 20200725032334.32f5cdf2@sidearm
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

When updating my table, my query was this:

update comic.panels set medium = x'2a958'::int where page = (
select page from comic.pages where comic = x'1db'::int and which = 0);

Unfortunately, I forgot that the column in the "pages" table was named "id" not "page".
This would have been the correct query:

update comic.panels set medium = x'2a958'::int where page = (
select id from comic.pages where comic = x'1db'::int and which = 0);

By itself, the bogus select causes an error:

select page from pages where comic = x'1db'::int and which = 0;
=>
ERROR: column "page" does not exist

When used in a subquery, the bogus select does not cause any error, and acts as a value
that is always equal to every other value. So "page = (SELECT page FROM pages WHERE ...)"
is always true for every value of "page", and now all 12,972 panels from every one of my
meticulously collected comics are nothing but image 2a958.

So... please have errors in subqueries cause the surrounding query to fail. That happens
for syntax errors, but for erroneous column errors it just silently updates all records in
the table to the same value. And... having a transactionless savepoint would be nice, so
I can test the database update in my other processes, then undo the catastrophic failure.

I'm using version 13devel, git commit 9f87ae38eaffcc7f72c45bfeb79e09dd6e8c2f48 so if the
bug has been fixed since then, feel free to ignore me.
-----BEGIN PGP SIGNATURE-----

iHQEAREIAB0WIQQ+4EYCR2lOGPl0mIHk9gahCsfaVgUCXxultgAKCRDk9gahCsfa
VjUjAP9l2HkceA2M/0z3qxjISRzDQBDgbtnyPx2LlydC6zJo3wD4tnar2sqXWxgT
d47a5XtzV9Orud7edYxDhHoJYFWMdA==
=q+wb
-----END PGP SIGNATURE-----

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Amit Kapila 2020-07-25 07:46:55 Re: Buffers from parallel workers not accumulated to upper nodes with gather merge
Previous Message tutiluren 2020-07-25 02:21:40 Re: pg_dump seems to be broken in regards to the "--exclude-table-data" option on Windows.