Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id C6EE82E018D for ; Tue, 11 Dec 2007 00:23:59 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 01043-04 for ; Tue, 11 Dec 2007 00:23:56 -0400 (AST) Received: from hosted05.westnet.com.au (hosted05.westnet.com.au [203.10.1.219]) by postgresql.org (Postfix) with ESMTP id A7B8E2E00A5 for ; Tue, 11 Dec 2007 00:23:56 -0400 (AST) Received: from hosted05.westnet.com.au (hosted05.westnet.com.au [127.0.0.1]) by hosted05.westnet.com.au (Postfix) with SMTP id CDA4E3F11C0 for ; Tue, 11 Dec 2007 13:23:53 +0900 (WST) Received: from mail.sael.com.au (dsl-124-148-1-69.qld.westnet.com.au [124.148.1.69]) by hosted05.westnet.com.au (Postfix) with ESMTP id 4C23A3F1108 for ; Tue, 11 Dec 2007 13:23:52 +0900 (WST) Received: from [192.168.3.103] (unknown [192.168.3.103]) by mail.sael.com.au (Postfix) with ESMTP id 048F017C0FE for ; Tue, 11 Dec 2007 14:21:29 +1000 (EST) Content-Disposition: inline From: Scott To: pgsql-sql@postgresql.org Subject: Insert Rule, Multiple Insert, Update Problem Date: Tue, 11 Dec 2007 14:23:52 +1000 User-Agent: KMail/1.9.5 MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200712111423.52950.lists@mail.sael.com.au> X-PMX-Branch: TNG-Outgoing X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200712/40 X-Sequence-Number: 29732 Hi, I am having trouble with an insert rule that also does an update. It works fine for a single insert but multiple inserts in a single statement don't behave as I expected. An outline of the problem is: A table "trans" has a "client_id" and a transaction amount called "points". Another table "clienst" also holds the "client_id" and an accumulated amount "total_points". I create a rule for the trans table: create rule trans_insert as on insert to trans do also update clients set total_points = total_points + NEW.points; where client_id = NEW.client_id; This works fine for a single insert but if I dump multiple transactions for multiple clients in the trans table only the first transaction for each client is accounted for in clients.total_points. I am just about to try and implement this as a trigger but it is driving me crazy as to why this won't work as a rule. If I put something like the following: insert into foo values(NEW.points); Then every transaction points value is copied to foo. Any help is very appreciated. Thanks, Scott.