Re: DELETING then INSERTING record with same PK in the same TRANSACTION

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Thomas Kellerer <shammat(at)gmx(dot)net>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: DELETING then INSERTING record with same PK in the same TRANSACTION
Date: 2022-02-09 22:23:01
Message-ID: CAKFQuwaz7nkfv2AAYr9GsoO3_R1-rhtBWobgbqv+4SX_f+fSkw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Feb 9, 2022 at 2:24 PM Thomas Kellerer <shammat(at)gmx(dot)net> wrote:

> David G. Johnston schrieb am 09.02.2022 um 21:47:
> > You cannot defer uniqueness checks to transaction commit so either it
> > is going to fail on the insert or it will not fail at all.
>
> You can defer unique constraints, but not primary key constraints.
>
>
Actually we are both wrong...

"This controls whether the constraint can be deferred. A constraint that is
not deferrable will be checked immediately after every command. Checking of
constraints that are deferrable can be postponed until the end of the
transaction (using the SET CONSTRAINTS command). NOT DEFERRABLE is the
default. Currently, only UNIQUE, PRIMARY KEY, EXCLUDE, and REFERENCES
(foreign key) constraints accept this clause."

https://www.postgresql.org/docs/current/sql-createtable.html

In any case I would not expect that primary key constraints would behave
differently than any other unique constraint. The null-ness check for a PK
cannot be deferred, however.

"NOT NULL and CHECK constraints are not deferrable. Note that deferrable
constraints cannot be used as conflict arbitrators in an INSERT statement
that includes an ON CONFLICT DO UPDATE clause."

David J.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Rama Krishnan 2022-02-09 23:41:07 Performance issue questions
Previous Message Thomas Kellerer 2022-02-09 21:24:14 Re: DELETING then INSERTING record with same PK in the same TRANSACTION