Re: CASCADE/fkey order - Mailing list pgsql-general

From Samuel Nelson
Subject Re: CASCADE/fkey order
Date
Msg-id CAC7xaNcR2L74_enJFtDSsdAqQdm1ZT-8_T+dfuyp2zXdBqfPHw@mail.gmail.com
Whole thread Raw
In response to Re: CASCADE/fkey order  ("David G. Johnston" <david.g.johnston@gmail.com>)
Responses Re: CASCADE/fkey order
Re: CASCADE/fkey order
List pgsql-general
I checked, and changing the `bazinga_foo_bar` constraint to:

alter table bazinga add constraint bazinga_foo_bar foreign key (foo_id, bar_id) references foo_bar (foo_id, bar_id) deferrable initially deferred;

seems to fix it to work as we were expecting.  Is that particularly costly?  Should I only set the constraint to be deferred when we really need it?  Would it be more efficient to perform the deletes explicitly within a transaction rather than relying on the cascades and deferring that one constraint?

Our resident ex-Oracle DBA said that deferred constraints used to be heavily recommended against, but he also admitted that he hasn't kept up with that in the past 10 years.

-Sam

https://github.com/nelsam

"As an adolescent I aspired to lasting fame, I craved factual certainty, and
I thirsted for a meaningful vision of human life -- so I became a scientist.
This is like becoming an archbishop so you can meet girls."
-- Matt Cartmill


On Wed, Jul 22, 2020 at 10:31 AM David G. Johnston <david.g.johnston@gmail.com> wrote:
On Wed, Jul 22, 2020 at 8:24 AM Samuel Nelson <valczir.darkvein@gmail.com> wrote:
Is there a way to force the delete to cascade to tables in a specific order?

No really, but you can defer constraint checking.


David J.
 

pgsql-general by date:

Previous
From: Ron
Date:
Subject: Re: Problem with pg_service.conf
Next
From: Adrian Klaver
Date:
Subject: Re: Problem with pg_service.conf