Re: Trigger loop question

From: Mike Nolan <nolan(at)gw(dot)tssi(dot)com>
To: gwood(at)ewebengine(dot)com (Gregory Wood)
Cc: tgl(at)sss(dot)pgh(dot)pa(dot)us (Tom Lane), pgsql-general(at)postgresql(dot)org (pgsql general list)
Subject: Re: Trigger loop question
Date: 2004-03-16 04:05:15
Message-ID: 200403160405.i2G45GKK027751@gw.tssi.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> I think this has more to do with whether the first trigger was fired
> BEFORE or AFTER the UPDATE. If the first trigger is fired BEFORE the
> UPDATE, then the second trigger (fired on the UPDATE) will not see the
> AFTER values of the first trigger. If you fire the first trigger as
> AFTER, I bet you'll see the changes.

Yes it does. OK, that means Tom's original suggestion of checking
the other table for the same value before updating it should prevent
an infinite loop, providing that's done from a pair of 'after update'
triggers, using the NEW.column entries in the triggered table to update
the other table.

This tested OK in both directions.

Of course, if I need to do any manipulation of the fields in the
table being updated by the SQL command, that will require a separate
'before update' trigger.
--
Mike Nolan

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stephen Robert Norris 2004-03-16 04:33:31 Re: Data Corruption in case of abrupt failure
Previous Message Andreas 2004-03-16 03:53:07 Re: Postmaster won't run as service on Cygwin