X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id EEF495E46BF for ; Fri, 20 Aug 2004 19:13:12 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 10790-05 for ; Fri, 20 Aug 2004 22:13:10 +0000 (GMT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id ABD865E40BB for ; Fri, 20 Aug 2004 19:13:08 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id i7KMD8iG014224 for ; Fri, 20 Aug 2004 22:13:08 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id i7KLjUwl006684 for pgsql-sql@postgresql.org; Fri, 20 Aug 2004 21:45:30 GMT From: "Sreten Milosavljevic" X-Newsgroups: comp.databases.postgresql.sql Subject: problem with RULE Date: Fri, 20 Aug 2004 23:17:08 +0200 Organization: Public news server of EUnet Yugoslavia Lines: 44 Message-ID: X-Complaints-To: abuse@EUnet.yu X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.8 tagged_above=0.0 required=5.0 tests=PRIORITY_NO_NAME X-Spam-Level: X-Archive-Number: 200408/268 X-Sequence-Number: 18765 I have two tables. One is test_main, and second is named result. Also I have view which summarizes results from test_main table and groups them by ID column: ************************ CREATE TABLE test_main(id varchar(4), value int4); CREATE TABLE result(id varchar(4), value int4); CREATE VIEW summing AS SELECT test_main.id, sum(test_main.value) AS suma GROUP BY test_main.id; ************************** And here is my problem: I want to make a rule which will insert new row in table result which will have ID and SUM value of that ID. ************************* CREATE RULE tester AS ON INSERT TO test_main DO INSERT INTO "result" (id, value) VALUES (new.id, summing.suma); ************************* So, when this rule is executed, for this INSERT commands: ************************* insert into test_main values('0003', 100) insert into test_main values('0004', 100) ************************* I get in column result: ************************* 0003, 100 0004, 100 0004, 100 ************************** and I need ********************* 0003, 100 0004, 100 Can anybody help me in doing this? Thanks in advance