Re: constraint deferred but fails? - Mailing list pgsql-admin

From Shreeyansh Dba
Subject Re: constraint deferred but fails?
Date
Msg-id CAGDYbUN3rm5fThzoeoxEo3F0VwK_MjBkqYXTC1BwcRafKAHujg@mail.gmail.com
Whole thread Raw
In response to constraint deferred but fails?  (Nagy László Zsolt <gandalf@shopzeus.com>)
List pgsql-admin
To automate this, you could define the foreign key constraint with ON DELETE CASCADE.
So when deleting first delete child rows and then parent.

Thanks & Regards,
Shreeyansh DBA Team
www.shreeyansh.com


On Thu, Jan 24, 2019 at 12:05 PM Nagy László Zsolt <gandalf@shopzeus.com> 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=>


pgsql-admin by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: constraint deferred but fails?
Next
From: Cory Nemelka
Date:
Subject: Re: Creation of temporary tables on a publisher