-- 创建失败时执行的触发函数 CREATEOR REPLACE FUNCTION func_test_trigger() RETURNStrigger LANGUAGE plpgsql AS $function$ BEGIN RAISE EXCEPTION 'Attention: can not update or delete table test_trigger,Please contact francs !'; END; $function$;
-- 建触发器,根据id限定行 createtrigger trigger_test_trigger_update BEFORE UPDATE ON test_user FOREACHROWWHEN (OLD.id in (1, 2, 3)) EXECUTEPROCEDURE func_test_trigger(); createtrigger trigger_test_trigger_delete BEFORE DELETEON test_user FOREACHROWWHEN (OLD.id in (1, 2, 3)) EXECUTEPROCEDURE func_test_trigger();
-- 限定行修改、删除时报错 UPDATE test_user set name ='123'where id =1; -- 执行报错 DELETEFROM test_user WHERE id =2; -- 执行报错