I am trying to write an audit trigger for a database in postgresql. This audit log should record date, time, user etc., but also the specific values that were updated. My challenge is in distinguishing values in an update action that were specifically requested from those that inherited from the previous value.
For example:
CREATE TABLE dummy_table (id SERIAL NOT NULL PRIMARY KEY, a INTEGER, b INTEGER);
INSERT INTO dummy_table (a,b) values (1,2);
UPDATE dummy_table SET (a) = (1) WHERE id = 1;
In this update the OLD and NEW records will both contain (a,b) = (1,2)
. But only a
was actually part of the update. Is it possible to detect this distinction in the trigger?