Re: Implementing cascading deletes on an existing table

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Culley Harrelson <culleyharrelson(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Implementing cascading deletes on an existing table
Date: 2001-03-21 15:28:01
Message-ID: Pine.BSF.4.21.0103210725510.34704-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Wed, 21 Mar 2001, Culley Harrelson wrote:

> Hi all,
>
> Im trying to find out the best way to implement cascading deletes on an
> existing table. I have this:
>
> create table fe_custom_set_card(
> custom_set_id int4 references fe_custom_set(custom_set_id) on delete
> cascade,
> card_id int4 references fe_card(card_id),
> card_sequence int2,
> category text,
> primary key(custom_set_id, card_id)
> );
>
> and I want to implement this:
>
> create table fe_custom_set_card(
> custom_set_id int4 references fe_custom_set(custom_set_id) on delete
> cascade,
> card_id int4 references fe_card(card_id) on delete cascade,
> card_sequence int2,
> category text,
> primary key(custom_set_id, card_id)
> );
>
> How do I go about making this transition? Dump the data, drop the
> table, recreate it and load the data?

It depends on how much work you're willing to do :)
I'd say, drop the three triggers associated with the second reference
(use drop trigger on them, you can find them by using the tgargs
and you need to quote the tgname when you use drop trigger) and
then use alter table to add the new constraint.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Hans-Jürgen Schönig 2001-03-21 15:31:49 Re: Compile PL/Perl
Previous Message Michael Fork 2001-03-21 15:04:31 Re: MACADDR types NULL value (undocumented?)