PostgreSQL – Disable Foreign Keys

PostgreSQL doesn’t have an explicit way to disable foreign keys. It does have a way to do so implicitly however because foreign keys are implemented via hidden triggers. If you need to disable foreign keys for a table load, etc it’s very easy:

ALTER TABLE <table name> DISABLE TRIGGER ALL;

It’s just as easy to reenable them:

ALTER TABLE <table name> ENABLE TRIGGER ALL;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s