I am new to PostgreSQL and found a trigger which serves my purpose completely except for one little thing. The trigger is quite generic and runs across different tables and logs different field changes. I found here.
What I now need to do is test for a specific field which changes as the tables change on which the trigger fires. I thought of using substr
as all the column will have the same name format e.g. XXX_cust_no
but the XXX can change to 2 or 4 characters. I need to log the value in theXXX_cust_no
field with every record that is written to the history_ / audit table. Using a bunch of IF
/ ELSE
statements to accomplish this is not something I would like to do.
The trigger as it now works logs the table_name
, column_name
, old_value
, new_value
. I however need to log the XXX_cust_no
of the record that was changed as well.
EXECUTE
to extract fields fromOLD
orNEW
dynamically. – Taxidermy