Re: How to temporarily disable a table's FK constraints?

From: Ron Johnson <ron(dot)l(dot)johnson(at)cox(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to temporarily disable a table's FK constraints?
Date: 2007-11-05 17:32:59
Message-ID: 472F53CB.1000707@cox.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 11/05/07 10:50, Kynn Jones wrote:
> Hi, everyone.
>
> Is there a standard way to disable a table foreign-key constraint temporarily?
>
> I thought that this would be a fairly common thing to want to do, but
> I only found this snippet online:
>
> -- to disable
> UPDATE pg_class SET reltriggers=0 WHERE relname = 'your_table';
>
> -- to re-enable
> UPDATE pg_class SET reltriggers = count( * )
> FROM pg_trigger WHERE pg_class.oid=tgrelid AND relname = 'your_table';
>
> and it appears that one needs to be root to execute these statements.
>
> Is there any other way for non-root users?

The whole idea of enforcing Relational Integrity in the database
engine is to *not* allow "regular users" to bypass data integrity
checks.

- --
Ron Johnson, Jr.
Jefferson LA USA

Give a man a fish, and he eats for a day.
Hit him with a fish, and he goes away for good!

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD4DBQFHL1PLS9HxQb37XmcRAm7zAKDbdYSymz3zIyKmfdU5wPjtpVTAlwCYoEA/
DI1Z2Fbgo62k6C2P8gsCQQ==
=Np96
-----END PGP SIGNATURE-----

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Keith Carr 2007-11-05 17:45:13 Bitemporal sequenced unique constraint (function/trigger)
Previous Message Erik Jones 2007-11-05 17:05:31 Re: How to temporarily disable a table's FK constraints?