pgsql触发器

1、设置自动更新时间戳方法

在使用finereport填报时,时间无法更新导致为空值,所以需要使用触发器,插入一条数据就插入时间。

(1)定义触发器函数

create or replace function track_forecast_date()  
 returns trigger as 
$$
begin 
    new.dmonth=current_timestamp ;
     return new ;
end
$$
language plpgsql ;
--track_forecast_date() 定义函数的名称
--dmonth 表中更新时间戳字段名称

 

(2)创建触发器

create trigger cs_forecast_name
before insert on forecast
for each row execute procedure track_forecast_date()
;
--cs_forecast_name 触发器名称
--forecast表名
--track_forecast_date() 触发器所需要的函数名称

 

posted @ 2023-01-03 10:48  小王同学学编程  阅读(552)  评论(0)    收藏  举报
levels of contents