Re: Partial update on an postgres upsert violates constraint - Mailing list pgsql-general

From Andreas Terrius
Subject Re: Partial update on an postgres upsert violates constraint
Date
Msg-id CA+gNo8sPN5e161zcQ3jhz_t-YC2ghmYLRxHkYuW9Z0F1qo4Y8g@mail.gmail.com
Whole thread Raw
In response to Re: Partial update on an postgres upsert violates constraint  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Partial update on an postgres upsert violates constraint  (John R Pierce <pierce@hogranch.com>)
Re: Partial update on an postgres upsert violates constraint  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Is there any way to check whether the row already exists before checking constraints ? I still want it to fail if it turns out to be a new row (which would violate the not null constraint), but updates the row if it already exists.

Since if that is not possible, I would need to do a query to determine whether the row exists in the database which kinda eliminates the use of upsert. (in this case, partial upsert). 



On Sun, Nov 20, 2016 at 3:57 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Adrian Klaver <adrian.klaver@aklaver.com> writes:
> ... So looks like constraints are checked before you get to the ON CONFLICT section.

Right.  ON CONFLICT is a means for dealing with duplicate-key errors in
the specified (or inferred) unique index.  It is *not* an all-purpose
error catcher.  In the case at hand, the given INSERT request fails due
to not-null constraints that are unrelated to what the ON CONFLICT clause
tests for.

                        regards, tom lane

pgsql-general by date:

Previous
From: Melvin Davidson
Date:
Subject: Thank you
Next
From: azhwkd
Date:
Subject: query locks up when run concurrently