Re: BUG #16706: insert into on conflict(pk) do update error violates not-null constraint

From: Vik Fearing <vik(at)postgresfriends(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, zhongxuchen(at)gmail(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #16706: insert into on conflict(pk) do update error violates not-null constraint
Date: 2020-11-09 19:45:13
Message-ID: de53948f-ff64-95dd-222e-cd0233d3399f@postgresfriends.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 11/9/20 4:16 PM, Tom Lane wrote:
> PG Bug reporting form <noreply(at)postgresql(dot)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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2020-11-09 20:15:01 Re: BUG #16706: insert into on conflict(pk) do update error violates not-null constraint
Previous Message Tom Lane 2020-11-09 17:18:34 Re: REL_13_STABLE Windows 10 Regression Failures