pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Fuhr <mike@fuhr.org>
To: Ari Johannesson <arividar@simnet.is>
Cc: pgsql-admin@postgresql.org
Subject: Re: How to temporarily disable referntial integrity?
Date: Sat, 11 Dec 2004 11:21:46 -0700
Message-ID: <20041211182146.GA39964@winnie.fuhr.org> (raw)
In-Reply-To: <iss.433ab781.185b.41b5f39b.b0b25.2f@quasar.skima.is>
References: <iss.433ab781.185b.41b5f39b.b0b25.2f@quasar.skima.is>

On Tue, Dec 07, 2004 at 06:17:48PM -0000, Ari Johannesson wrote:

> I have data to import into a postgres database. The data is referentially
> sound but during the insert it breaks som foreign-key constraints. Is there
> a way to turn off the referential integrity during the insert?

You could make the foreign key constraints deferrable and use SET
CONSTRAINTS to defer all or some of them.

CREATE TABLE foo (id INTEGER PRIMARY KEY);
CREATE TABLE bar (id INTEGER REFERENCES foo DEFERRABLE);

BEGIN;
SET CONSTRAINTS bar_id_fkey DEFERRED;
INSERT INTO bar VALUES (1);
INSERT INTO foo VALUES (1);
COMMIT;

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/



view thread (2+ messages)

Message-ID: <20041211182146.GA39964@winnie.fuhr.org>
Permalink:  ../20041211182146.GA39964@winnie.fuhr.org/
Also on:    postgresql.org/message-id/20041211182146.GA39964@winnie.fuhr.org

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: mike@fuhr.org, arividar@simnet.is
  Subject: Re: How to temporarily disable referntial integrity?
  In-Reply-To: <20041211182146.GA39964@winnie.fuhr.org>
  References: <iss.433ab781.185b.41b5f39b.b0b25.2f@quasar.skima.is> <20041211182146.GA39964@winnie.fuhr.org>

* 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