1、首先需要通过代码创建函数,也就是定义触发器。
CREATE OR REPLACE FUNCTION "public"."sys_shijianchuo"()
RETURNS "pg_catalog"."trigger" AS $BODY$
begin
new.updated_time= current_timestamp;
return new;
end
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100
注释:sys_shijianchuo():为你定义函数的名称。
updated_time:为你表中更新时间戳字段名称(pgsql不可以大写的)。
其他的不用管执行就可以了。此过程只能通过sql实现.
2、接下来就是创建触发器了
create trigger shijianchuo before INSERT OR update on flowinst for each row execute procedure sys_shijianchuo();
注释:shijianchuo:触发器名称,可以随意设置,但是不要设置成中文的。
flowinst:表名
sys_shijianchuo():触发器所要用的函数名称,与第一步函数名称保持一致。
INSERT OR update 【插入、更新同时触发用 or 】