Re: bug in delete rule ?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: sferriol <sylvain(dot)ferriol(at)imag(dot)fr>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: bug in delete rule ?
Date: 2004-03-25 16:59:06
Message-ID: 12432.1080233946@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

sferriol <sylvain(dot)ferriol(at)imag(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Shelby Cain 2004-03-25 17:08:31 Re: Memory usage during vacuum
Previous Message Uwe C. Schroeder 2004-03-25 16:49:58 Re: Memory usage during vacuum