Skip site navigation (1) Skip section navigation (2)

Re: Ueberpruefung von FOREIGN_KEYS abschalten

From: Andreas Kretschmer <akretschmer(at)spamfence(dot)net>
To: pgsql-de-allgemein(at)postgresql(dot)org
Subject: Re: Ueberpruefung von FOREIGN_KEYS abschalten
Date: 2008-11-29 08:24:06
Message-ID: 20081129082405.GA7263@tux (view raw or flat)
Thread:
Lists: pgsql-de-allgemein
Thomas Steinbach <steinbach(at)gmx-topmail(dot)de> schrieb:

> Hallo,
>
> gibt es bei PostgreSQL sowas wie ein
>
> "SET FOREIGN_KEY_CHECKS=0;"
>
> wie bei MySQL?

Du kannst RI-Constraints deferrable setzen:

test=# create table m (id int primary key);
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "m_pkey"
for table "m"
CREATE TABLE
Zeit: 28,950 ms
test=*# create table s (f int references m deferrable initially
deferred);
CREATE TABLE
Zeit: 2848,866 ms
test=*#
test=*#
test=*#
test=*# insert into s values (1);
INSERT 0 1
Zeit: 0,375 ms
test=*# commit;
ERROR:  insert or update on table "s" violates foreign key constraint "s_f_fkey"
DETAIL:  Key (f)=(1) is not present in table "m".


Dann schlagen diese erst beim COMMIT zu.



Andreas
-- 
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°

In response to

pgsql-de-allgemein by date

Next:From: Albe LaurenzDate: 2008-12-01 10:49:34
Subject: Re: Ueberpruefung von FOREIGN_KEYS abschalten
Previous:From: Thomas SteinbachDate: 2008-11-24 11:55:29
Subject: Ueberpruefung von FOREIGN_KEYS abschalten

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group