pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Vik Fearing <vik@postgresfriends.org>
Cc: 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, 09 Nov 2020 15:15:01 -0500
Message-ID: <1996438.1604952901@sss.pgh.pa.us> (raw)
In-Reply-To: <de53948f-ff64-95dd-222e-cd0233d3399f@postgresfriends.org>
References: <16706-08837c0cdaf4ce57@postgresql.org>
	<1974489.1604935011@sss.pgh.pa.us>
	<de53948f-ff64-95dd-222e-cd0233d3399f@postgresfriends.org>

Vik Fearing <vik@postgresfriends.org> writes:
> On 11/9/20 4:16 PM, Tom Lane wrote:
>> I get
>> ERROR:  null value in column "name" violates not-null constraint
>> DETAIL:  Failing row contains (4, null, 6).

> That's the complaint.

Oh ... it wasn't expressed very well then.  I thought the OP was
reporting that the not-null constraint wasn't being enforced,
which surely *would* be a bug.

> 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.

			regards, tom lane





view thread (7+ messages)  latest in thread

Message-ID: <1996438.1604952901@sss.pgh.pa.us>
Permalink:  ../1996438.1604952901@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1996438.1604952901@sss.pgh.pa.us

 · 

reply

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: tgl@sss.pgh.pa.us, vik@postgresfriends.org, 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: <1996438.1604952901@sss.pgh.pa.us>

* 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