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();

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章