X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id DB96E3A63C6 for ; Sat, 11 Dec 2004 18:21:53 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 04145-04 for ; Sat, 11 Dec 2004 18:21:50 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 1D5CA3A6351 for ; Sat, 11 Dec 2004 18:21:50 +0000 (GMT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.1/8.13.1) with ESMTP id iBBILlQU005978 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 11 Dec 2004 11:21:49 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.1/8.13.1) with ESMTP id iBBILkri039999; Sat, 11 Dec 2004 11:21:46 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.1/8.13.1/Submit) id iBBILk7W039998; Sat, 11 Dec 2004 11:21:46 -0700 (MST) (envelope-from mfuhr) Date: Sat, 11 Dec 2004 11:21:46 -0700 From: Michael Fuhr To: Ari Johannesson Cc: pgsql-admin@postgresql.org Subject: Re: How to temporarily disable referntial integrity? Message-ID: <20041211182146.GA39964@winnie.fuhr.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.105 tagged_above=0 required=5 tests=AWL, UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200412/98 X-Sequence-Number: 15684 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/