Re: Rule problem - Mailing list pgsql-sql

From Tom Lane
Subject Re: Rule problem
Date
Msg-id 19317.1023978960@sss.pgh.pa.us
Whole thread Raw
In response to Rule problem  (Svenn Helge Grindhaug <svenn@ii.uib.no>)
List pgsql-sql
Svenn Helge Grindhaug <svenn@ii.uib.no> writes:
> create rule a_delete as
> on delete to a do
> delete from b where id1 = old.id1;

> create rule c_delete as
> on delete to c do
> delete from a where id1 = (select id1 from b where id2 = old.id2);

The a_delete rule is run before the actual "DELETE FROM a" command,
so by the time the latter runs, the b row is gone, and no match exists.

I'd be inclined to think about doing this with foreign keys (set up
for ON DELETE CASCADE) instead of handmade rules.  If you really want
to do it by hand, triggers will probably work better than rules.
        regards, tom lane


pgsql-sql by date:

Previous
From: "Dmitri Colebatch"
Date:
Subject: Re: join question - three tables, two with foreign keys to the first
Next
From: Manfred Koizar
Date:
Subject: Re: join question - three tables, two with foreign keys to the first