Re: How to REMOVE an "on delete cascade"?

From: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "Phoenix Kiula *EXTERN*" <phoenix(dot)kiula(at)gmail(dot)com>, "PG-General Mailing List" <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to REMOVE an "on delete cascade"?
Date: 2013-06-28 12:55:11
Message-ID: A737B7A37273E048B164557ADEF4A58B17BC1D9E@ntex2010a.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Phoenix Kiula wrote:
> Hi. Hard to find this command in the documentation - how should I alter a table to REMOVE the "on
> delete cascade" constraint from a table? Thanks.

Unless you want to mess with the catalogs directly, I believe that
you have to create a new constraint and delete the old one, like:

Table "laurenz.b"
Column | Type | Modifiers
--------+---------+-----------
b_id | integer | not null
a_id | integer | not null
Indexes:
"b_pkey" PRIMARY KEY, btree (b_id)
"b_a_id_ind" btree (a_id)
Foreign-key constraints:
"b_a_id_fkey" FOREIGN KEY (a_id) REFERENCES a(a_id) ON DELETE CASCADE

ALTER TABLE b ADD CONSTRAINT scratch FOREIGN KEY (a_id) REFERENCES a(a_id);

ALTER TABLE b DROP CONSTRAINT b_a_id_fkey;

ALTER TABLE b RENAME CONSTRAINT scratch TO b_a_id_fkey;

Yours,
Laurenz Albe

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Christoph Berg 2013-06-28 13:09:37 Re: Why are there no inequality scans for ctid?
Previous Message David Greco 2013-06-28 12:45:01 AFTER triggers and constraints