beginners trigger problem - Mailing list pgsql-general

From Hakan Kuecuekyilmaz
Subject beginners trigger problem
Date
Msg-id 3A158AD4.FA928F6D@fht-esslingen.de
Whole thread Raw
List 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@fht-esslingen.de

pgsql-general by date:

Previous
From: "Martin A. Marques"
Date:
Subject: Re: [HACKERS] Re: PHPBuilder article -- Postgres vs MySQL
Next
From: Alexander Jerusalem
Date:
Subject: Re: I know installation questions are boring ...