开启与禁用自定义触发器
程序员文章站
2022-06-07 14:41:41
...
代码
CREATE OR REPLACE FUNCTION func_disable_triggers()
RETURNS INTEGER
AS
$BODY$
DECLARE
rec record;
BEGIN
for rec in select tgrelid::regclass::varchar as table_name,tgname from pg_trigger where tgname like '%notify%'
loop
execute format('alter table %1$s disable trigger %2$s', rec.table_name, rec.tgname);
end loop;
RETURN 0;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;
CREATE OR REPLACE FUNCTION func_enable_triggers()
RETURNS INTEGER
AS
$BODY$
DECLARE
rec record;
BEGIN
for rec in select tgrelid::regclass::varchar as table_name,tgname from pg_trigger where tgname like '%notify%'
loop
execute format('alter table %1$s enable trigger %2$s', rec.table_name, rec.tgname);
end loop;
RETURN 0;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;