--po_info为主表,po_item为从表,po_info中有更新字段lastupdatetime,两张表关联字段po_id
---------------po_id用触发器监控表的更新,用lastupdatetime记录时间------------------ --创建触发器过程-- CREATE OR REPLACE FUNCTION po_info() RETURNS trigger AS $BODY$ BEGIN If (TG_OP = 'UPDATE') THEN If NEW.lastupdatetime = OLD.lastupdatetime Then update po_info set lastupdatetime = now() where po_id=new.po_id ; END IF; END IF; return null; end; $BODY$ LANGUAGE plpgsql --创建触发器-- CREATE TRIGGER tr_po_info AFTER update ON po_info FOR EACH ROW EXECUTE PROCEDURE po_info(); ---------------po_item用触发器监控表的更新,更改po_id的lastupdatetime时间------------------ --创建触发器过程-- CREATE OR REPLACE FUNCTION po_item() RETURNS trigger AS $BODY$ BEGIN If (TG_OP = 'UPDATE') THEN If (NEW != OLD) Then update po_info p1 set lastupdatetime = now() where p1.po_id=new.po_id ; END IF; END IF; return null; end; $BODY$ LANGUAGE plpgsql --创建触发器-- CREATE TRIGGER tr_po_item AFTER update ON po_item FOR EACH ROW EXECUTE PROCEDURE po_item();