Re: [EXTERNAL]: Re: UPSERT in Postgres

From: Alban Hertroys <haramrae(at)gmail(dot)com>
To: Louis Tian <louis(dot)tian(at)aquamonix(dot)com(dot)au>
Cc: Peter Geoghegan <pg(at)bowt(dot)ie>, "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: [EXTERNAL]: Re: UPSERT in Postgres
Date: 2023-04-09 09:26:16
Message-ID: C1A7991E-251B-4422-AB4B-C1531D863036@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> On 7 Apr 2023, at 2:49, Louis Tian <louis(dot)tian(at)aquamonix(dot)com(dot)au> wrote:

(…)

> I am not expecting an error here. The problem is with no conflict it always go down the insert path first and results in a not null constraint error.
> While I am expecting the insert is never executed in the first place when that row already exist (as identified by it primary key). So the update execute without error.
> I hope the pesudo code above is enough to clarify the difference?

Your assumption on what the problem is, is not correct. The problem is not with the conflict resolution, it is with your statement violating a not null constraint.

It doesn’t matter whether you insert first or update first, either operation is going to violate that constraint. You’re specifying a NULL value for a column that doesn’t accept that because it has a NOT NULL constraint. That is your problem.

Alban Hertroys
--
There is always an exception to always.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Francisco Olarte 2023-04-09 09:32:11 Re: [EXTERNAL]: Re: UPSERT in Postgres
Previous Message Louis Tian 2023-04-09 02:46:33 Re: [EXTERNAL]: Re: [EXTERNAL]: Re: UPSERT in Postgres