pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Ron <ronljohnsonjr@gmail.com>
To: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Purpose of DEFERRABLE _and_ INITIALLY DEFERRED foreign key constraint checking?
Date: Wed, 3 Aug 2022 21:45:22 -0700
Message-ID: <05b30f5d-ae4e-edb1-7691-8ef0d867617f@aklaver.com> (raw)
In-Reply-To: <d4b46cee-6223-609e-7c0f-0925bd6cd55a@gmail.com>
References: <d7529945-a3a3-f5fe-9c63-08703f2c3825@gmail.com>
	<0317c0c5-a7e5-9073-01b9-80391491108b@aklaver.com>
	<d4b46cee-6223-609e-7c0f-0925bd6cd55a@gmail.com>

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.klaver@aklaver.com





view thread (7+ messages)  latest in thread

Message-ID: <05b30f5d-ae4e-edb1-7691-8ef0d867617f@aklaver.com>
Permalink:  ../05b30f5d-ae4e-edb1-7691-8ef0d867617f@aklaver.com/
Also on:    postgresql.org/message-id/05b30f5d-ae4e-edb1-7691-8ef0d867617f@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, ronljohnsonjr@gmail.com
  Subject: Re: Purpose of DEFERRABLE _and_ INITIALLY DEFERRED foreign key constraint checking?
  In-Reply-To: <05b30f5d-ae4e-edb1-7691-8ef0d867617f@aklaver.com>
  References: <d7529945-a3a3-f5fe-9c63-08703f2c3825@gmail.com> <0317c0c5-a7e5-9073-01b9-80391491108b@aklaver.com> <d4b46cee-6223-609e-7c0f-0925bd6cd55a@gmail.com> <05b30f5d-ae4e-edb1-7691-8ef0d867617f@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox