From: Mitch Vincent <mitch@venux.net>
To: pgsql-sql@postgreSQL.org
Subject: Rule Question
Date: Sun, 19 Dec 1999 16:40:37 -0500
Message-ID: <01bb01bf4a69$b0fdae60$0300000a@doot.org> (raw)
Boy, I'm just full of questions this weekend. On with another one..
The overall objective here is to have the field "total" on an invoice
calculated every time the table is updated, so it's always up to date. I
could do this programatically but there are so many ways that this can
change, it would be great if Postgre just did it for me every time :-)
From what I read about rules, this is possible so what I did was this :
Created this function to do the totalling:
create function total_up(int4) returns float8 as 'select fee_membership +
fee_logins + fee_convention + fee_prints+ fee_hotlines + fee_postage +
fee_ups + fee_late + fee_other1 + fee_other2 + fee_other3 + fee_pastdue from
invoice where invoice_number = $1;' language 'sql';
And this rule to call the function and update the invoice that has been
updated, inserting the new total. :
create rule total_invoice as on update to invoice where
invoice_number=NEW.invoice_number DO update invoice set total =
total_up(NEW.invoice_number) where invoice_number=NEW.invoice_number;
However I get this when I do an update on an invoice:
PostgreSQL Error: 1 (ERROR: query rewritten 10 times, may contain cycles )
Session halted.
Some kind of loop? Well, I didn't see any kind of loop or error but that is
probably due to my little understanding of rules..
Thanks yet again!
-Mitch
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: mitch@venux.net
Subject: Re: Rule Question
In-Reply-To: <01bb01bf4a69$b0fdae60$0300000a@doot.org>
References: <01bb01bf4a69$b0fdae60$0300000a@doot.org>
* 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