Re: ON DELETE CASCADE

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Tim Perdue <tim(at)perdue(dot)net>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: ON DELETE CASCADE
Date: 2002-12-12 17:11:08
Message-ID: 20021212090519.A8841-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


On Thu, 12 Dec 2002, Tim Perdue wrote:

> I'm trying to comb through my database and add ON DELETE CASCADE to a
> number of tables where I already have fkeys in place, but I'm having a
> hard time.
>
> ALTER TABLE project_task DROP CONSTRAINT
> "project_task_group_project_id_f" RESTRICT;
>
> ERROR: ALTER TABLE / DROP CONSTRAINT: project_task_group_project_id_f
> does not exist

I think this works in 7.3, but that's the first version in which it does.

> ALTER TABLE project_task
> ADD CONSTRAINT projecttask_groupprojectid_fk
> FOREIGN KEY (group_project_id)
> REFERENCES project_group_list(group_project_id) ON DELETE CASCADE;
> NOTICE: ALTER TABLE will create implicit trigger(s) for FOREIGN KEY
> check(s)
> ALTER
>
> That command works, but now I think I have 2x as many triggers as I
> want. How do I get rid of the original triggers?

You'll need to look at pg_trigger and find the triggers associated with
the constraints. I'd suggest removing both sets and then using alter
table again because then you can look for triggers that have the correct
tables and columns listed in tgargs. As a note there are two triggers on
project_group_list for each constraint as well and you'll need to remove
those too.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Marie G. Tuite 2002-12-12 17:26:24 Re: ON DELETE CASCADE
Previous Message Tim Perdue 2002-12-12 17:01:11 ON DELETE CASCADE