NEW and OLD as ROWS

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

NEW and OLD as ROWS

Craig Servin-2
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

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org
Reply | Threaded
Open this post in threaded view
|

Re: NEW and OLD as ROWS

Michael Fuhr
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/

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match