Is this possible in a trigger? - Mailing list pgsql-general

From Fernando
Subject Is this possible in a trigger?
Date
Msg-id 4820C821.4060903@ggtours.ca
Whole thread Raw
Responses Re: Is this possible in a trigger?  (Klint Gore <kgore4@une.edu.au>)
Re: Is this possible in a trigger?  (hubert depesz lubaczewski <depesz@depesz.com>)
List 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.

pgsql-general by date:

Previous
From: "James B. Byrne"
Date:
Subject: Rules to provide a virtual column
Next
From: Alex Vinogradovs
Date:
Subject: xlogdump & pgview