Re: UPDATE keyword - Mailing list pgsql-general

From will trillich
Subject Re: UPDATE keyword
Date
Msg-id 20010602041112.C10951@serensoft.com
Whole thread Raw
In response to UPDATE keyword  ("Ian Harding" <ianh@healthdept.co.pierce.wa.us>)
List 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
haverun 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!

pgsql-general by date:

Previous
From: will trillich
Date:
Subject: Re: How to access arrays from DBD::Pg?
Next
From: will trillich
Date:
Subject: Re: pl-perl setup?