Is this possible in a trigger?

From: Fernando <fernando(at)ggtours(dot)ca>
To: pgsql-general(at)postgresql(dot)org
Subject: Is this possible in a trigger?
Date: 2008-05-06 21:05:37
Message-ID: 4820C821.4060903@ggtours.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I want to keep a history of changes on a field in a table. This will be
the case in multiple tables.

Can I create a trigger that loops the OLD and NEW values and compares
the values and if they are different creates a change string as follows:

e.g;

FOR EACH field IN NEW
IF field.value <> OLD.field.name THEN
changes := changes
|| field.name
|| ' was: '
|| OLD.field.value
|| ' now is: '
|| field.value
|| '\n\r';
END IF
END FOR;

Your help is really appreciated.

Thank you.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alex Vinogradovs 2008-05-06 21:20:54 xlogdump & pgview
Previous Message Ken Allen 2008-05-06 19:45:57 Cannot update table with OID with linked server in SQl Server