X-Original-To: pgsql-admin@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 3DD35474E5C for ; Wed, 19 Feb 2003 21:24:42 -0500 (EST) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with SMTP id 24267-05 for ; Wed, 19 Feb 2003 21:24:31 -0500 (EST) Received: from snickers.hotpop.com (snickers.hotpop.com [204.57.55.49]) by postgresql.org (Postfix) with ESMTP id 8CDAC474E4F for ; Wed, 19 Feb 2003 21:24:31 -0500 (EST) Received: from bonbon.net (kubrick.hotpop.com [204.57.55.16]) by snickers.hotpop.com (Postfix) with SMTP id 61275722D1 for ; Thu, 20 Feb 2003 02:24:33 +0000 (UTC) Received: from yudha (unknown [61.5.113.68]) by smtp-1.hotpop.com (Postfix) with SMTP id 1C6D82F8113; Thu, 20 Feb 2003 02:24:27 +0000 (UTC) Message-ID: <004c01c2d887$d801b3d0$ea00a8c0@yudha> From: "Yudha Setiawan" To: , "Stephan Szabo" References: <20030219082219.G34399-100000@megazone23.bigpanda.com> Subject: Re: How to avoid the Mutating Triggers ?? Date: Thu, 20 Feb 2003 09:29:00 +0700 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.00.2919.6700 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 X-HotPOP: ----------------------------------------------- Sent By HotPOP.com FREE Email Get your FREE POP email at www.HotPOP.com ----------------------------------------------- X-Virus-Scanned: by amavisd-new X-Archive-Number: 200302/325 X-Sequence-Number: 7523 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 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