Re: avoiding endless loop in an UPDATE trigger

From: Louis-David Mitterrand <vindex(at)apartia(dot)ch>
To: "Norman J(dot) Clarke" <norman(at)combimatrix(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: avoiding endless loop in an UPDATE trigger
Date: 2001-03-04 12:18:38
Message-ID: 20010304131837.D15968@apartia.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Feb 26, 2001 at 11:53:51AM -0800, Norman J. Clarke wrote:
> Hello,
>
> I am attempting to write a trigger function or rule in pl/pgsql that runs
> on UPDATE to a table named "nodes". From inside this trigger, I would like
> to UPDATE the same "nodes" table. How can I do this without entering into
> an endless loop?

What I did is add a no_update bool to the table and test:

if new.no_update = true then
new.no_update = false;
else
<do your update here>
new.no_update = true;
endif

--
Observe, reason, and experiment.
(if you're too dumb, just pray)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Louis-David Mitterrand 2001-03-04 12:22:04 Re: Trigger sending an eMail
Previous Message Jan Wieck 2001-03-04 12:07:24 Re: triggers vs "NEW" pseudorecord