天天看点

PGSQL触发器实例

---创建触发器执行的函数
CREATE OR replace FUNCTION tri_assets_in_update()
returns trigger as $$
begin

IF (new.total_invt-OLD.total_invt) > 0
THEN
  insert into assets_in(code,ast_id,in_number,name,property,specs,brand,class,unit,location) values(new.code,NEW.id,new.total_invt-OLD.total_invt,NEW.name,NEW.property,NEW.specs,NEW.brand,NEW.class,NEW.unit,NEW.location);
end if;
return null;
end;
$$
language plpgsql;

--创建触发器本身
create   trigger trigger_assets_in_update

after update on assets_info

FOR EACH ROW execute procedure tri_assets_in_update();