Reputation: 55
is it posible to get the name of the column in which a value was change after an insert or update?, i know that with TG_TABLE_NAME you get the table name in which the value was change, but i want to get the column name is it posible?
Upvotes: 0
Views: 41
Reputation: 9756
The changed columns could be determined by checking the values of the OLD and NEW for each column, for example:
IF (OLD.col1 IS DISTINCT FROM NEW.col1) THEN 'col1';
ELSIF (OLD.col2 IS DISTINCT FROM NEW.col2) THEN 'col2';
...
I suspect you could do some interesting "except" work on the OLD
and NEW
variables, or a FOR
loop over the NEW variable, so that you don't have hard-code the column list.
Upvotes: 2