Home > Archive > PostgreSQL Discussion > January 2006 > comparing OLD and NEW in update trigger..









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author comparing OLD and NEW in update trigger..
Alex Mayrhofer

2006-01-26, 4:57 pm


Hi there,

i'm using the following trigger function to update a timestamp of a row when
it is UPDATEd:

CREATE OR REPLACE modified_trigger() RETURNS opaque AS $$
BEGIN
NEW.modify_timestamp := now();
END;
$$ LANGUAGE SQL;

Since i like to use the same trigger for various tables, i'm planning to
keep it very generic.

What i'd like to do now is to just update the modify_timestamp column if OLD
and NEW are different. I'd LOOP over the row elements, and compare each
column of OLD with NEW, and bailing out if there's a difference.

I'd appreciate your help on the following two questions:

- How can i get the column names of NEW/OLD? Is there a set returning
function for this?

- Is there a more efficient way to compare whole rows?

thanks,

Alex Mayrhofer
---
http://nona.net/features/map/

---------------------------(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

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com