Re: update rule loops - Mailing list pgsql-sql

From Stephan Szabo
Subject Re: update rule loops
Date
Msg-id Pine.BSF.4.10.10008180819210.1321-100000@megazone23.bigpanda.com
Whole thread Raw
In response to update rule loops  ("Poul L. Christiansen" <plc@faroenet.fo>)
List pgsql-sql
On Fri, 18 Aug 2000, Poul L. Christiansen wrote:

> Hi
> 
> I'm trying to make a field in my table (datechanged) to automatically be
> updated with the value 'now()' when an update on the table occurs.
> 
> plc=# create rule datechanged_radius AS ON update to radius do update
> radius set datechanged ='now()';
> CREATE 22025360 1
> plc=# update radius set destinationip = '212.055.059.001';
> ERROR:  query rewritten 10 times, may contain cycles
> 
> This means that it's going in a loop, because the rule triggers itself.
> 
> Is there another way to do this?

Two ways I can think of are either have a "view" where you do the work
on the view, but the underlying table is named something else, which
means you actually need to do an instead rule that does the update on
that table and the setting of datechanged. (Not 100% sure of this, 
but should work).

Second is use triggers.  Write a pl/pgsql before update trigger.
Assigning to NEW.datechanged should work I believe.





pgsql-sql by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: Continuous inserts...
Next
From: Craig Johannsen
Date:
Subject: Re: [GENERAL] Re: variables in SQL??