动态分配触发器名称postgresql

Dynamically assign trigger name postgresql

嗨,我有一个 Registra_cambios () 函数;想要分配给我数据库中的所有 tables,我想知道你是否可以将触发器名称与记录(table 名称)连接起来,我的光标在所有 [=18 上都不具有相同的触发器名称=]s

创建触发器示例t_log_ "record" ()

CREATE OR REPLACE FUNCTION ActiveTriggers() returns  void as $$
DECLARE

 r record;
c CURSOR FOR SELECT table_name as tab FROM information_schema.tables WHERE table_schema='public' AND table_type='BASE TABLE';


BEGIN

  FOR r IN c LOOP
        create trigger t_log_r before insert or update or delete
        on r.tab
        for each row
        execute procedure Registra_cambios();
  END LOOP;




END;
$$ LANGUAGE plpgsql;

诸如此类?..

do
$$
declare
  r record;
begin
  for r in (SELECT table_name as tab FROM information_schema.tables WHERE table_schema='public' AND table_type='BASE TABLE';) loop
    execute 'create trigger t_log_r_'||r.tab||' before insert or update or delete
    on '||r.tab||'
    for each row
    execute procedure Registra_cambios()';
  end loop;
end;
$$
;