pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-admin@lists.postgresql.org
Subject: Re: constraint deferred but fails?
Date: Thu, 24 Jan 2019 01:01:27 -0600
Message-ID: <fcf3589d-7f24-c12a-18d2-54cac14ea1c0@gmail.com> (raw)
In-Reply-To: <7db1a61c-1f0e-d233-0756-b7eecf2f420d@shopzeus.com>
References: <7db1a61c-1f0e-d233-0756-b7eecf2f420d@shopzeus.com>

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.

view thread (6+ messages)  latest in thread

Message-ID: <fcf3589d-7f24-c12a-18d2-54cac14ea1c0@gmail.com>
Permalink:  ../fcf3589d-7f24-c12a-18d2-54cac14ea1c0@gmail.com/
Also on:    postgresql.org/message-id/fcf3589d-7f24-c12a-18d2-54cac14ea1c0@gmail.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 using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: ronljohnsonjr@gmail.com, pgsql-admin@lists.postgresql.org
  Subject: Re: constraint deferred but fails?
  In-Reply-To: <fcf3589d-7f24-c12a-18d2-54cac14ea1c0@gmail.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