Arie
Arie

Reputation: 3543

Disable all constraints besides uniques

What is the query to disable all constraints like foreign keys, primary keys but leave uniques?

Upvotes: 0

Views: 38

Answers (1)

pifor
pifor

Reputation: 7882

PostgreSQL does not allow to disable constraints generally speaking. You can only disable foreign key constraints by disabling the related trigger used to implement the foreign keys.

See https://www.postgresql.org/docs/12/sql-altertable.html#SQL-ALTERTABLE-NOTES

DISABLE/ENABLE [ REPLICA | ALWAYS ] TRIGGER

One can disable or enable a single trigger specified by name, or all triggers on the table, or only user triggers (this option excludes internally generated constraint triggers such as those that are used to implement foreign key constraints or deferrable uniqueness and exclusion constraints). Disabling or enabling internally generated constraint triggers requires superuser privileges; it should be done with caution since of course the integrity of the constraint cannot be guaranteed if the triggers are not executed.

Upvotes: 1

Related Questions