From: Yudha Setiawan <yudha@BonBon.net>
To: pgsql-admin@postgresql.org
To: Stephan Szabo <sszabo@megazone23.bigpanda.com>
Subject: Re: How to avoid the Mutating Triggers ??
Date: Thu, 20 Feb 2003 09:29:00 +0700
Message-ID: <004c01c2d887$d801b3d0$ea00a8c0@yudha> (raw)
References: <20030219082219.G34399-100000@megazone23.bigpanda.com>
Dear Szabo, You were wrote;
> Well, what have you tried? For the simple
> case (pointer is not changing), a not terribly
> efficient version might be something like:
>
> create or replace function dorecalcupd() returns trigger as
> 'declare
> last int;
> begin
> SELECT INTO last qty FROM foo where pointer < NEW."pointer" ORDER BY
> pointer desc LIMIT 1;
> NEW.qty := last + NEW."in" - NEW."out";
> if (NEW.pointer = OLD.POINTER AND (NEW."in" != OLD."in" or NEW."out" !=
> OLD."out")) then
> UPDATE foo set qty = (select sum(f."in") - sum(f."out") from foo f where
> f.pointer<pointer)
> where pointer>NEW.pointer;
> end if;
> return NEW;
> end;' language 'plpgsql';
>
> In this case the trigger does cause requests to the same trigger for the
> later rows, but since only qty is changing it does nothing.
>
> It's more complicated when you deal with the pointer moving case.
Thank's a Lot for all milist especialy for dear Stephan Szabo. I'm Sorry
"Pointer" on my ilustration "IS NOT a FIELD". it's just information for
me, to show you where is exactly the position of record / Pointer that
I want to Change.
Perhaps you have another best one, please...??
Thank You very much and,
GOD Bless You All.
Yudha Setiawan.
VoIP
No. : 628899911223344
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-admin@postgresql.org
Cc: yudha@BonBon.net, sszabo@megazone23.bigpanda.com
Subject: Re: How to avoid the Mutating Triggers ??
In-Reply-To: <004c01c2d887$d801b3d0$ea00a8c0@yudha>
References: <20030219082219.G34399-100000@megazone23.bigpanda.com> <004c01c2d887$d801b3d0$ea00a8c0@yudha>
* 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