Re: UPDATE keyword
Will Trillich <will@serensoft.com>
From: will trillich <will@serensoft.com>
To: pgsql-general@postgresql.org
Date: 2001-06-02T09:11:12Z
Lists: pgsql-general
On Fri, May 25, 2001 at 04:16:00PM -0700, Ian Harding wrote: > Well, I am making progress in rewriting my MSSQL Server T-SQL triggers and stored procedures in Pl/Tcl. However, I have run into a bit of an issue and I wonder if anyone knows the best way to address it... > > In T-SQL triggers, you can use the UPDATE keyword in conditional expressions as in > > IF UPDATE(myfield) > BEGIN > do something > END > > It detects the update of the field. I have been comparing > $NEW(myfield) and $OLD(myfield) which works ok, except where I > used the UPDATE() test as a crutch. I sometimes do an update > like > > UPDATE mytable SET myfield = myfield WHERE... > > to fire an update trigger, and executing only the code in that trigger surrounded by UPDATE(myfield). > > Is there an easy way to duplicate this, or should I work around it? how about create view relationname as select * from _real_relation_name_; create rule on update to relationname do instead ( update _real_relation_name_ set fld=new.fld, col=new.col, modified=current_timestamp, differencefield=old.something-new.something, whatever=some_function() ; insert into _some_tracking_relation_ ( field, list, here ) values ( ... ) ); check out the manuals for 'create rule'. very handy stuff. -- #95: We are waking up and linking to each other. We are watching. But we are not waiting. -- www.cluetrain.com will@serensoft.com http://sourceforge.net/projects/newbiedoc -- we need your brain! http://www.dontUthink.com/ -- your brain needs us!