Re: constraint deferred but fails?

From: Ron <ronljohnsonjr(at)gmail(dot)com>
To: pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: constraint deferred but fails?
Date: 2019-01-24 07:01:27
Message-ID: fcf3589d-7f24-c12a-18d2-54cac14ea1c0@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On 1/24/19 12:35 AM, Nagy László Zsolt wrote:
> Hello,
>
> I have deferred the only fk constraint to this table inside a
> transaction, but I still cannot delete rows from it.
>
> How is that possible?
>
>
> master=> ALTER TABLE doc.display_mode disable trigger user;
> ALTER TABLE
> master=> BEGIN;
> BEGIN
> master=> SET CONSTRAINTS doc.fk_book_display_mode_id DEFERRED;
> SET CONSTRAINTS
> master=> DELETE FROM doc.display_mode;
> ERROR:  update or delete on table "display_mode" violates foreign key
> constraint "fk_book_display_mode_id" on table "book"
> DETAIL:  Key (id)=(1) is still referenced from table "book".
> master=>

Deferring a constraint doesn't mean "disappearing" the constraint; it just
means... *deferring* it until later (i.e. commit time).  It's only purpose
is to allow your code to delete from doc.display_mode before deleting from
book .  But you *do* have to delete from book at some point in the transaction.

--
Angular momentum makes the world go 'round.

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message David G. Johnston 2019-01-24 07:08:47 Re: constraint deferred but fails?
Previous Message Nagy László Zsolt 2019-01-24 06:42:18 Re: constraint deferred but fails?