rule problem - Mailing list pgsql-general

From
Subject rule problem
Date
Msg-id 025b01c1d3f7$ae46c160$6501a8c0@calvin
Whole thread Raw
Responses Re: rule problem
List 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




pgsql-general by date:

Previous
From: "Miguel Carvalho"
Date:
Subject: BUG? - Sequence got verry strange id
Next
From:
Date:
Subject: Could someone tell me what is wrong withthis function