beginners trigger problem

From: Hakan Kuecuekyilmaz <hakubw00(at)fht-esslingen(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: beginners trigger problem
Date: 2000-11-17 19:45:24
Message-ID: 3A158AD4.FA928F6D@fht-esslingen.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

hello,

i have following table:
id b_stueck b_name b_preis b_summe
(units) (price) (sum)

i want b_summe automatically be calculated, therefore i use
following trigger:
CREATE RULE summieren AS ON INSERT TO t_bestand DO UPDATE t_bestand SET
b_summe=(b_stueck*b_preis) FROM t_bestand

after all, i get following result:

webliste=# INSERT INTO t_bestand(b_stueck, b_name, b_preis)
VALUES(1,'CD','20');
INSERT 0 2
webliste=# SELECT * FROM t_bestand;
id | b_stueck | b_name | b_preis | b_summe
----+----------+------------+---------+----------
1 | 3 | Festplatte | DM49,00 | DM147,00
2 | 4 | Disketten | DM45,00 | DM180,00
5 | 1 | CD | DM20,00 |
6 | 1 | CD | DM20,00 |
(4 rows)

the row is doubled,

any hints why and how the b_summe be calculated automatically??

thanks in advance
--
Hakan Kuecuekyilmaz FHT-Esslingen University of Applied Sciences,
Germany
hakubw00(at)fht-esslingen(dot)de

Browse pgsql-general by date

  From Date Subject
Next Message Alexander Jerusalem 2000-11-17 19:49:50 Re: I know installation questions are boring ...
Previous Message Martin A. Marques 2000-11-17 19:08:26 Re: [HACKERS] Re: PHPBuilder article -- Postgres vs MySQL