Re: deleting from a view

From: Alfred Perlstein <bright(at)wintelcom(dot)net>
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:14:57
Message-ID: 20001017161457.F272@fw.wintelcom.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

* shawn everett <everett(at)pgweb(dot)com> [001017 16:08] 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 :)
>
> I've tried splitting things up and using two rules however the second rule
> always fails. I suspect that's becuase old.prod_date is set to null.
>
> Any tips or advice would be greatly aprecated.

Blind guess, define a SQL or plpgsql function, call it from your rule.

--
-Alfred Perlstein - [bright(at)wintelcom(dot)net|alfred(at)freebsd(dot)org]
"I have the heart of a child; I keep it in a jar on my desk."

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Simcich 2000-10-17 23:36:01 RE: DOUBLE MESSAGE
Previous Message shawn everett 2000-10-17 23:04:10 deleting from a view