Re: Trigger loop question - Mailing list pgsql-general

From Mike Nolan
Subject Re: Trigger loop question
Date
Msg-id 200403160223.i2G2NfqZ026622@gw.tssi.com
Whole thread Raw
In response to Re: Trigger loop question  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Trigger loop question
List pgsql-general
> Mike Nolan <nolan@gw.tssi.com> writes:
> > If I set up an on update trigger for table 'A' that updates the
> > corresponding column in table 'B', and one for table 'B' that updates
> > the corresponding column in table 'A', does that create an endless loop?
>
> Yes.
>
> You could break the loop perhaps by not issuing an UPDATE if the data is
> already correct in the other table.

The trigger on table 'A' is obviously going to see both the old value and the
new value for the column.  If it queries table 'B', it would see
the current value there.

However, if I update table 'B' and the 2nd trigger fires, that trigger
will still see the OLD value if does a query on table 'A', since I
think transaction atomic rules require that any updated values aren't
made available to the outside world (including other triggers) until the
transaction is complete.

I tested this, and the 2nd trigger still sees the original value of
the field from the first table, which I think is the proper result.
--
Mike Nolan


pgsql-general by date:

Previous
From: Mage
Date:
Subject: Re: boolean to int
Next
From: Andreas
Date:
Subject: Re: Postmaster won't run as service on Cygwin