From: Vik Fearing <vik@postgresfriends.org>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: zhongxuchen@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16706: insert into on conflict(pk) do update error violates not-null constraint
Date: Mon, 9 Nov 2020 20:45:13 +0100
Message-ID: <de53948f-ff64-95dd-222e-cd0233d3399f@postgresfriends.org> (raw)
In-Reply-To: <1974489.1604935011@sss.pgh.pa.us>
References: <16706-08837c0cdaf4ce57@postgresql.org>
<1974489.1604935011@sss.pgh.pa.us>
On 11/9/20 4:16 PM, Tom Lane wrote:
> PG Bug reporting form <noreply@postgresql.org> writes:
>> example:
>> CREATE TABLE TEST1 (
>> id varchar(100) NOT NULL,
>> name varchar(100) NOT NULL,
>> status varchar(100) NOT NULL,
>> CONSTRAINT test1_pkey PRIMARY KEY (id)
>> )
>
>> insert into TEST1 (ID, NAME,STATUS ) values('4','test','6') ;
>> insert into TEST1 as t1 (ID, NAME,STATUS ) values('4',null,'6') on conflict
>> (id) do update set NAME=COALESCE(excluded.NAME,t1.NAME),
>> STATUS=COALESCE(excluded.STATUS,t1.STATUS);
>
> I get
>
> ERROR: null value in column "name" violates not-null constraint
> DETAIL: Failing row contains (4, null, 6).
That's the complaint.
> so this seems to have been fixed already.
I think the issue is the not null constraint is evaluated before the ON
CONFLICT and so there is no chance to "heal" the row by coalescing the
old and new values.
--
Vik Fearing
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: vik@postgresfriends.org, tgl@sss.pgh.pa.us, zhongxuchen@gmail.com, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16706: insert into on conflict(pk) do update error violates not-null constraint
In-Reply-To: <de53948f-ff64-95dd-222e-cd0233d3399f@postgresfriends.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