From: | Ernest Chiarello <ernest(at)dr7(dot)cnrs(dot)fr> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org, georget(at)admin(dot)in2p3(dot)fr |
Subject: | create rule and last record |
Date: | 2001-03-26 15:27:19 |
Message-ID: | 3ABF5FD7.40D45FEF@dr7.cnrs.fr |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
i use a "create rule on insert" in order to obtain the
sum on the column montant in the column cumul.
but the last record of the table is never updated. why ?
DROP
CREATE
DROP
CREATE
CREATE 9606604 1
INSERT 9606605 1
id | montant | cumul
-----+------+-------
toto | 10 |
(1 row)
INSERT 9606606 1
id | montant | cumul
-----+------+-------
toto | 10 | 10
toto | 20 |
(2 rows)
here are the queries :
drop table test3;
create table test3 (id char(10), montant float8, cumul float8);
drop function somme(bpchar);
create function somme(bpchar) returns float8 as
'select sum(montant) from test3 where
id = \$1' language 'sql';
create rule example_rule as
on insert to test3
do
update test3 set cumul = somme(new.id);
insert into test3 (id,montant) values ('toto','10');
select * from test3;
insert into test3 (id,montant) values ('toto','20');
select * from test3;
--
Ernest CHIARELLO, chiarello(at)dr7(dot)cnrs(dot)fr, Tel:04-72-44-56-77, Fax:04-72-44-56-73
CNRS - Delegation Vallee du Rhone
2 avenue Albert Einstein 69609 VILLEURBANNE CEDEX - FRANCE
From | Date | Subject | |
---|---|---|---|
Next Message | Colby Meyer | 2001-03-27 17:14:50 | Problems accessing TCL functions |
Previous Message | Mo Holkar | 2001-03-26 08:47:36 | Re: Error creating user |