Thread: NEW and OLD as ROWS

NEW and OLD as ROWS

From
Craig Servin
Date:
I am writing an update trigger that I want to fire when any field changes.  It 
looks like two ROWS can be compared very easily, but not the two RECORDS OLD 
and NEW.

Is there a way to do:

NEW IS DISTINCT FROM OLD

in a trigger?

This would help me not have to write a specific trigger for each table.

Thanks,

Craig


Re: NEW and OLD as ROWS

From
Michael Fuhr
Date:
On Wed, Aug 03, 2005 at 12:52:24PM -0500, Craig Servin wrote:
> Is there a way to do:
> 
> NEW IS DISTINCT FROM OLD
> 
> in a trigger?
> 
> This would help me not have to write a specific trigger for each table.

One way would be to write the trigger function in a language other
than PL/pgSQL (PL/Tcl, PL/Perl, PL/Python, etc., depending on whether
the language in question supports triggers in the version of
PostgreSQL you're using).  Some languages' trigger functions receive
NEW and OLD in variables that can be inspected without knowing the
table structure in advance, so you can write generic functions that
will work on any table.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/