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

From valgog
Subject Re: Is this possible in a trigger?
Date
Msg-id f07961da-729f-4c89-b951-32514511871b@2g2000hsn.googlegroups.com
Whole thread Raw
In response to Is this possible in a trigger?  (Fernando <fernando@ggtours.ca>)
List pgsql-general
On May 6, 11:05 pm, ferna...@ggtours.ca (Fernando) wrote:
> 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.

in plpgsql you could

select new into textVar;

and then do acrobatics with the text value of that record... or
converting the text value into a known table record type with EXECUTE
'select ' || quote_literal(textVar) || '::tableRecord' INTO
tableRecordVar statement. But the field names are to be extracted from
the catalog anyway.

Or use plperl or plpython :(


pgsql-general by date:

Previous
From: hubert depesz lubaczewski
Date:
Subject: Re: Is this possible in a trigger?
Next
From: Jan Christian Dittmer
Date:
Subject: Import German Decimal Numbers