Re: Purpose of DEFERRABLE _and_ INITIALLY DEFERRED foreign key constraint checking?

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Ron <ronljohnsonjr(at)gmail(dot)com>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Purpose of DEFERRABLE _and_ INITIALLY DEFERRED foreign key constraint checking?
Date: 2022-08-04 04:45:22
Message-ID: 05b30f5d-ae4e-edb1-7691-8ef0d867617f@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 8/3/22 18:13, Ron wrote:
> On 8/3/22 20:02, Adrian Klaver wrote:
>> On 8/3/22 17:30, Ron wrote:
>>> AWS RDS Postgresql 12.10

>
> And https://www.postgresql.org/docs/12/sql-set-constraints.html seems to
> say that SET CONSTRAINTS can make DEFERRABLE FKs temporarily not
> deferrable.
>
> What's the point?

The way I think of it is:

1) CONSTRAINTS are something that is supposed to constrain an action.

2) Setting DEFERRABLE is a cheat code to push 1) out to the end of a
transaction by using INITIALLY DEFERRED.

3) If the constraint was created/altered to DEFERRABLE INITIALLY
DEFERRED the SET CONSTRAINTS IMMEDIATE unsets the cheat code in a given
transaction. Maybe for most cases you want the check done at the end of
the transaction, but in a specific case you need that check to happen
before another statement occurs prior to the end of the transaction.

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Martin Kalcher 2022-08-04 05:46:10 Re: [PATCH] Introduce array_shuffle() and array_sample()
Previous Message houzj.fnst@fujitsu.com 2022-08-04 02:51:59 RE: Support logical replication of DDLs