I have several tables and want to log when changes are made to them, what the change was and who made the change. Postgresql 9.2
CREATE TABLE unitsref (
unitsrefid serial primary key,
units varchar,
unitname varchar,
inuse boolean,
systemuse varchar,
keynotes integer,
linkid integer
);
Is the best practise to use OLD.* IS DISTINCT FROM NEW.* ?
CREATE TRIGGER log_unitsref
AFTER UPDATE ON unitsref
FOR EACH ROW
WHEN (OLD.* IS DISTINCT FROM NEW.*)
EXECUTE PROCEDURE log_unitsref();
I am only really interested in the three fields:
units varchar,
unitname varchar,
inuse boolean,
I want to record these changes in a table eventlog with the fields:
recordtype varchar,
recordkey varchar,
changetype varchar,
personid integer,
changedate date,
changetime time,
changefrom varchar,
changeto varchar,
What is the best syntax to write a function to do this? In Progress Openedge I would write
create EventLog.
assign EventLog.PersonId = glb-Personid
EventLog.RecordType = "UnitsRef"
EventLog.RecordKey = UnitsRef.Units
EventLog.ChangeType = "Create"
EventLog.changeFrom = ""
EventLog.changeTo = ""
EventLog.changeDate = today
EventLog.changeTime = time
but I don`t know the best method in Postgresql