Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 871979FB461 for ; Wed, 1 Nov 2006 15:35:02 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 95272-03-2 for ; Wed, 1 Nov 2006 19:34:46 +0000 (UTC) X-Greylist: delayed 00:27:00.197791 by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id E4C3F9FB863 for ; Wed, 1 Nov 2006 13:17:43 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from bedrock.cromagnon.com (smtp.cromagnon.com [170.215.19.8]) by svr4.postgresql.org (Postfix) with ESMTP id 84C5A5AF027 for ; Wed, 1 Nov 2006 16:50:42 +0000 (GMT) Received: from lt-cservin.cdhps.com (mail.mpaygateway.com [209.98.143.247]) (authenticated bits=0) by bedrock.cromagnon.com (8.13.8/8.13.8) with ESMTP id kA1GodRQ003012 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 1 Nov 2006 10:50:41 -0600 From: Craig Servin Organization: Cro-Magnon To: pgsql-sql@postgresql.org Subject: Statement Triggers and access to other rows in the transaction Date: Wed, 1 Nov 2006 10:50:33 -0600 User-Agent: KMail/1.9.4 X-MailKey: craigkey MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200611011050.33562.cservin@cromagnon.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.537 tagged_above=0 required=5 tests=BAYES_20, FORGED_RCVD_HELO, SPF_FAIL X-Spam-Level: X-Archive-Number: 200611/7 X-Sequence-Number: 26659 I have tables representing a ledger system and the accounts on which it operates. I want to do 2 things to all transactions altering the ledger tables. First, all of the inserts into the ledger tables should be balanced ( They should sum to 0 ). If not I want to abort the transaction. Second, if the transaction is balanced I want to update the account balance on the account tables. In other database systems that I have used when you have a statement level trigger you get access to the inserted/updated/deleted rows from that transaction as "virtual" tables within the trigger that you can manipulate. I am currently using plpgsql to write my triggers. I have not been able to figure out the "right" way to do this in PostgreSQL and would appreciate any advice. Thanks, Craig