From: Jack Kerkhof <jack.kerkhof@guest-tek.com>
To: pgsql-sql@postgresql.org
Subject: Trigger to identify which column(s) updated
Date: Thu, 15 Jan 2004 14:15:01 -0700
Message-ID: <ENEIKKAEJOFHOIHMMOIDKEAFCJAA.jack.kerkhof@guest-tek.com> (raw)
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: jack.kerkhof@guest-tek.com
Subject: Re: Trigger to identify which column(s) updated
In-Reply-To: <ENEIKKAEJOFHOIHMMOIDKEAFCJAA.jack.kerkhof@guest-tek.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox