Re: Rules WHERE condition

From: Robert Fitzpatrick <robert(at)webtent(dot)com>
To: Michael Fuhr <mike(at)fuhr(dot)org>
Cc: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Rules WHERE condition
Date: 2004-11-17 17:49:30
Message-ID: 1100713770.29305.14.camel@columbus.webtent.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 2004-11-17 at 11:49, Michael Fuhr wrote:
> On Wed, Nov 17, 2004 at 11:20:41AM -0500, Robert Fitzpatrick wrote:
>
> > I have a view that used union all to merge three tables together. I was
> > hoping to create a rule, one for each table using the WHERE condition of
> > the rule to determine which table gets updated. Is this possible?
>
> See the CREATE RULE documentation:
>
> http://www.postgresql.org/docs/7.4/static/sql-createrule.html
>

Thanks, that explains a lot, but still not able to get my rule to work,
this is what I have now:

CREATE RULE "update_unconditional" AS ON UPDATE TO
"public"."viewdeterioratedlbp"
DO INSTEAD NOTHING;

CREATE RULE "update_xrf" AS ON UPDATE TO "public"."viewdeterioratedlbp"
WHERE ((new.note)::text = 'Unit'::text)
DO (UPDATE tblxrf SET deterioration = new.deterioration WHERE
(tblxrf.xrf_id = new.xrf_id););

ohc=# update viewdeterioratedlbp set deterioration = 'test' where xrf_id
= 143;
UPDATE 0

This is the first rule I have tried to setup, I read through the doc,
but don't seem to be able to catch what I'm doing wrong. Do I have to
update all fields for it to work?

--
Robert

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Robert Fitzpatrick 2004-11-17 18:28:16 Re: Rules WHERE condition
Previous Message Michael Fuhr 2004-11-17 16:49:22 Re: Rules WHERE condition