Re: bug in delete rule ? - Mailing list pgsql-general

From Tom Lane
Subject Re: bug in delete rule ?
Date
Msg-id 12432.1080233946@sss.pgh.pa.us
Whole thread Raw
In response to bug in delete rule ?  (sferriol <sylvain.ferriol@imag.fr>)
List pgsql-general
sferriol <sylvain.ferriol@imag.fr> writes:
> and i create a rule for deleting using the view:
> CREATE RULE ALL_CENTERS_DEL AS ON DELETE TO all_centers
> DO INSTEAD (
>     DELETE FROM center_var WHERE
>     center_id = OLD.center_id;
>     DELETE FROM center WHERE
>     center_id = OLD.center_id;
> );

> but i this rule delete only line in center_var
> and do not remove the line in center table

Once you delete the center_var row, there is no row in the view that
matches the id, so the comparison against OLD.center_id fails.

You could possibly make the view use an outer join, and be careful to
delete the dependent row first in the rule.  Or maybe one of the tables
can be given a foreign-key dependency on the other, with ON DELETE CASCADE
behavior, and then the view rule need only delete explicitly from the
master table.

            regards, tom lane

pgsql-general by date:

Previous
From: "Uwe C. Schroeder"
Date:
Subject: Re: Memory usage during vacuum
Next
From: Shelby Cain
Date:
Subject: Re: Memory usage during vacuum