rule problem

From: <tsmets(at)brutele(dot)be>
To: <pgsql-general(at)postgresql(dot)org>
Subject: rule problem
Date: 2002-03-25 12:21:13
Message-ID: 025b01c1d3f7$ae46c160$6501a8c0@calvin
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


I created the following tables :
test=> create table updatableArchivable ( pk serial, dateupdate timestamp
default current_timestamp, code char(10));
test=> create view tbl_vw as select code from updatableArchivable;
test=> create table archive ( pk int, dateupdate timestamp, code char(10),
dateend timestamp default current_timestamp);

My aim is to make some test to see the best way to solve archiving &
presenting things simply.
I currently could have the code on updatableArchivable unique for all
safetyness.

Now I created a rule so the user can update the VIEW, as follow :
test=> create rule tbl_vw_insert as
test-> on insert to tbl_vw
test-> do instead
test-> insert into updatablearchivable (code) values (new.code);

This one works !

Now I want to be able to UPDATE the view & automatically generate an
archiving of the old value into the updatableArchivable table into the
archive table.
I tried to do the following :
test=> create rule tbl_vw_update as
test-> on update to tbl_vw
test-> do instead
test-> begin work
test-> insert into archive (pk, dateupdate, code) values (old.pk,
old.dateupdate, code);

***but it generated the following ***
ERROR: parser: parse error at or near "begin"
test=> create rule test=> select * from father; _insert

I thought I could do smthg like :
do instead
begin work
Action_1;
Action_2;
Action_3;
commit work

Could some one suggest a better solution ?
I have never seen what happens if I set multiple rules.
Are they applied in the order they were created ?

Much tx,

thomas,

--
Thomas SMETS
rue J. Wytsmanstraat 62
1050 Bruxelles
yahoo-id : smetsthomas

Responses

Browse pgsql-general by date

  From Date Subject
Next Message tsmets 2002-03-25 14:36:27 Could someone tell me what is wrong withthis function
Previous Message Miguel Carvalho 2002-03-25 11:30:27 BUG? - Sequence got verry strange id