rule problem
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
tsmets@brutele.be wrote:
[...]
I thought I could do smthg like :
do instead
begin work
Action_1;
Action_2;
Action_3;
commit workCould 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 ?
You cannot and don't need to do BEGIN and COMMIT as rule
actions. Write it as
do instead
(
Action_1;
Action_2;
Action_3;
);
and the actions will be perfomed in that order, all in one
and the same transaction.
Jan
--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck@Yahoo.com #
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
There is only one thing I cannotprotect myself from is my own stupidity !
Tx very much to remind me that
:-))))))
thomas,
--
Thomas SMETS
rue J. Wytsmanstraat 62
1050 Bruxelles
yahoo-id : smetsthomas
----- Original Message -----
From: "Jan Wieck" <janwieck@yahoo.com>
To: <tsmets@brutele.be>
Cc: <pgsql-general@postgresql.org>
Sent: 25 March, 2002 7:48 PM
Subject: Re: [GENERAL] rule problem
Show quoted text
tsmets@brutele.be wrote:
[...]
I thought I could do smthg like :
do instead
begin work
Action_1;
Action_2;
Action_3;
commit workCould 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 ?You cannot and don't need to do BEGIN and COMMIT as rule
actions. Write it asdo instead
(
Action_1;
Action_2;
Action_3;
);and the actions will be perfomed in that order, all in one
and the same transaction.Jan
--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck@Yahoo.com #_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com