Re: how to temporally disable foreign key constraint check

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: how to temporally disable foreign key constraint check
Date: 2011-10-21 17:04:14
Message-ID: j7s8m5$nl0$1@dough.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Emi Lu wrote on 21.10.2011 15:36:
> Good morning,
>
>
> Is there a way to temporally disabled foreign key constraints something like
>
> SET FOREIGN_KEY_CHECKS=0
>
> When population is done, will set FOREIGN_KEY_CHECKS=1
>
> Thanks a lot!
> Emi
>
You can define the FKs as "DEFERRABLE INITIALLY IMMEDIATE".

Then at the start of your transaction you can defer constraint checking until you commit everything using:

SET CONSTRAINTS ALL DEFERRED;

Thomas

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Craig Ringer 2011-10-21 23:51:27 Re: how to temporally disable foreign key constraint check
Previous Message Emi Lu 2011-10-21 15:47:19 Re: how to temporally disable foreign key constraint check