我有几张表,想记录对它们进行更改的时间、更改的内容以及更改的人员。PostgreSQL 9.2
CREATE TABLE unitsref (
unitsrefid serial primary key,
units varchar,
unitname varchar,
inuse boolean,
systemuse varchar,
keynotes integer,
linkid integer
);
使用 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();
我只对三个领域真正感兴趣:
units varchar,
unitname varchar,
inuse boolean,
我想将这些更改记录在带有以下字段的表事件日志中:
recordtype varchar,
recordkey varchar,
changetype varchar,
personid integer,
changedate date,
changetime time,
changefrom varchar,
changeto varchar,
编写函数来执行此操作的最佳语法是什么?在进行中 Openedge 我会写
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
但我不知道 Postgresql 中的最佳方法