pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Sreten Milosavljevic <range@net.yu>
To: pgsql-sql@postgresql.org
Subject: problem with  RULE
Date: Fri, 20 Aug 2004 23:17:08 +0200
Message-ID: <cg5pm9$n2u$1@news.eunet.yu> (raw)

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





Message-ID: <cg5pm9$n2u$1@news.eunet.yu>
Permalink:  ../cg5pm9$n2u$1@news.eunet.yu/
Also on:    postgresql.org/message-id/cg5pm9$n2u$1@news.eunet.yu

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: range@net.yu
  Subject: Re: problem with  RULE
  In-Reply-To: <cg5pm9$n2u$1@news.eunet.yu>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox