Skip site navigation (1) Skip section navigation (2)

Trigger to identify which column(s) updated

From: "Jack Kerkhof" <jack(dot)kerkhof(at)guest-tek(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Trigger to identify which column(s) updated
Date: 2004-01-15 21:15:01
Message-ID: ENEIKKAEJOFHOIHMMOIDKEAFCJAA.jack.kerkhof@guest-tek.com (view raw or flat)
Thread:
Lists: pgsql-sql
Does anyone know how to write a trigger that would identify which columns
have actually changed in an update (and then log them to an archive).

I suspect that the function would look something like;

CREATE FUNCTION FIND_CHANGED_COLUMNS() RETURNS OPAQUE AS '
BEGIN

   -- FOR EACH COLUMN IN THE RECORD:
      -- IF ( NEW COLUMNx <> OLD COLUMNx)
         -- LOG THE RECORD PRIMARY KEY, COLUMN NAME, OLD VALUE

   RETURN NEW;
END;
' LANGUAGE 'plpgsql';

In other words
	- How might you parse, in general, old and new records to compare like
columns?
      - How can you find out the primary key of a record?

Thanks, Jack


Responses

pgsql-sql by date

Next:From: denisDate: 2004-01-16 04:32:09
Subject: Initially Deffered - FK
Previous:From: Chris BowlbyDate: 2004-01-15 19:06:01
Subject: Re: Problem with plpgsql function

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group