X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id C0FA3D1B44E for ; Thu, 4 Mar 2004 14:54:47 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 60021-10 for ; Thu, 4 Mar 2004 10:54:46 -0400 (AST) Received: from hm61.locaweb.com.br (hm61.locaweb.com.br [200.213.197.161]) by svr1.postgresql.org (Postfix) with SMTP id 60D03D1C94B for ; Thu, 4 Mar 2004 10:54:37 -0400 (AST) Received: (qmail 17632 invoked from network); 4 Mar 2004 14:51:58 -0000 Received: from hm10.locaweb.com.br (200.246.179.88) by hm61.locaweb.com.br with QMTP; 4 Mar 2004 14:51:58 -0000 Received: (qmail 32238 invoked by uid 41632); 4 Mar 2004 14:54:07 -0000 Message-ID: <20040304145407.32236.qmail@hm10.locaweb.com.br> From: "Rodrigo Sakai" Date: Thu, 4 Mar 2004 11:54:07 -0300 To: pgsql-sql@postgresql.org Subject: How to avoid (stop) a endless loop in a trigger References: In-Reply-To: X-Mailer: LocaMail X-IPAddress: 200.168.66.138 X-Sender: rodrigo@2bfree.com.br MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200403/36 X-Sequence-Number: 17135 Hi people, i have a problem here. I'm doing a trigger that when a update occurs i need to do an update on the same table (target table), but as known, it causes a endless loop whithin infinit updates. So I need to stop the trigger after it does the first update, is there any way????? I tried to do a return null, but that was a very bad idea because it stops completly the function fired by a trigger and all its computation is in vain... The test trigger that i did is like : CREATE OR REPLACE FUNCTION public.sp_teste_loop() RETURNS trigger AS ' begin raise notice \'Trigger Fired\'; if (TG_OP = \'INSERT\') then update teste_trigger set flg_bool = \'S\' where codigo=NEW.codigo; RETURN NEW; elsif (TG_OP = \'UPDATE\') then update teste_trigger set flg_bool = \'N\' where codigo=NEW.codigo; RETURN NULL; end if; end; ' LANGUAGE 'plpgsql' VOLATILE; CREATE TRIGGER tr_sp_teste_trigger BEFORE INSERT OR UPDATE ON public.teste_trigger FOR EACH ROW EXECUTE PROCEDURE public.sp_teste_loop(); Thank for any help and regards!!!! ===================== Rodrigo Sakai Database Programmer rodrigo@2bfree.com.br http://www.2bfree.com.br Tel: (55) (11) 5083-5577 Fax: (55) (11) 5549-3598 =====================