create table test(id int,name varchar, create_time timestamp without time zone default now(), modify_time timestamp without time zone );
create table tbl_log(id int, log_time timestamp without time zone);CREATE OR REPLACE FUNCTION func_update_modify_time()
RETURNS trigger
AS
$BODY$
DECLARE
BEGINraise notice 'TG_OP=%',TG_OP;if TG_OP='UPDATE' or TG_OP ='INSERT' then insert into tbl_log values(NEW.id,clock_timestamp());return NEW;end if;RETURN NULL;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;drop trigger if exists trig_test_modify on test;
create trigger trig_test_modify after insert or update on test for each row execute function func_update_modify_time();insert into test values(id,name,create_time) select n , 'name'||n, clock_timestamp()::timestamp without time zone from generate_series(1,100) as t(n)