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

From: Andres Freund <andres(at)anarazel(dot)de>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Vik Fearing <vik(at)postgresfriends(dot)org>, zhongxuchen(at)gmail(dot)com, 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-10 04:25:24
Message-ID: 20201110042524.voeknzrrke7hschl@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi,

On 2020-11-09 15:15:01 -0500, Tom Lane wrote:
> Vik Fearing <vik(at)postgresfriends(dot)org> writes:
> > 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.
>
> Ah. Well, ON CONFLICT is for resolving duplicate-key errors;
> it's not a get-out-of-jail-free card for every sort of error.
>
> I think the right way to handle this example would be with a
> before-update trigger, which IIRC can modify the row before
> we apply any table constraint checks.

Sounds like the to-be-upserted row could never be inserted, but only
updated. In which case an UPDATE sounds more appropriate than an INSERT
... ON CONFLICT SET ... - am I missing something?

Greetings,

Andres Freund

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Andres Freund 2020-11-10 04:31:27 Re: BUG #16707: Memory leak
Previous Message Burgess, Freddie 2020-11-09 23:32:54 Re: pg_dump error attempting to upgrade from PostgreSQL 10 to PostgreSQL 12