From: | Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> |
---|---|
To: | shawn everett <everett(at)pgweb(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: deleting from a view |
Date: | 2000-10-17 23:37:52 |
Message-ID: | Pine.BSF.4.10.10010171633490.78204-100000@megazone23.bigpanda.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Tue, 17 Oct 2000, shawn everett wrote:
> Before I get flamed for not RTFM I do know I can use a rule to do this.
>
> Here's the problem:
>
> I have a view that is made up of two tables.
>
> When I delete from the view I would like the records to be deleted from
> both tables that make up my view. What is the best way to accomplish
> this?
>
> Should I use a trigger or a rule? If I use a trigger how should it be
> written. If I use a rule how do I put two delete statements in it.
>
> I'd like to be able to do something along the lines of:
>
> CREATE RULE view_raw_reman_prod_delete3 AS
> ON DELETE TO view_raw_reman_prod
> DO INSTEAD
> 'BEGIN
> DELETE FROM reman_costraw1 WHERE prod_date=old.prod_date;
> DELETE FROM reman_cost_total_raw1 WHERE prod_date=old.prod_date;
> END;';
>
> This doesn't work :)
IIRC, the correct syntax for multiple actions is
CREATE RULE ...
DO INSTEAD (
<action>;
<action>;
);
(My test set was three tables a b and c, each having a column named a
which was an int, and my rule was
create rule rule as on delete to a do instead (
delete from b where a=OLD.a; delete from c where a=OLD.a);
which appeared to work in my minimal test (delete a row from
a and see what happens)
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2000-10-17 23:43:32 | Re: deleting from a view |
Previous Message | Michael Simcich | 2000-10-17 23:36:01 | RE: DOUBLE MESSAGE |