From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: maximaximax@gmail.com
Subject: BUG #16150: UPDATE set NULL value in non-null columns
Date: Thu, 05 Dec 2019 09:17:34 +0000
Message-ID: <16150-dc6886080d71e985@postgresql.org> (raw)
The following bug has been logged on the website:
Bug reference: 16150
Logged by: Maxim Votyakov
Email address: maximaximax@gmail.com
PostgreSQL version: 12.0
Operating system: Windows
Description:
Hi guys
Today I found a big problem, I can write a valid UPDATE which put NULL value
in non-null column.
Let's create a domain, two tables and insert 1 row into them:
create domain d_text_not_null as text default '' not null;
create table person (name d_text_not_null);
create table town (name d_text_not_null);
insert into person(name) values ('test');
insert into town(name) values ('test2');
select * from person; -- 1 row with value test
Now let's try to update person name to null. It failed and it is correct:
update person set name = null; -- SQL Error [23502]: ERROR: domain
d_text_not_null does not allow null values
But now let's try to update person name to with sub-query. It updates a row
without any problem:
update person set name = (select name from town where name = 'wrong'); -- 1
row updated
Let's check data and see the result:
select * from person; -- 1 row with value NULL in non-null column !!!
I think it is very dangerous and important bug and it has to be fixed to not
damage data in databases - if I backup/restore such tables they become
empty.
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: noreply@postgresql.org, maximaximax@gmail.com
Subject: Re: BUG #16150: UPDATE set NULL value in non-null columns
In-Reply-To: <16150-dc6886080d71e985@postgresql.org>
References: <16150-dc6886080d71e985@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