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