我想宣布几个触发器并将它们分配给单个脚本中的多个表。
create or replace function trigger_a()
returns trigger language plpgsql as $$
begin
new.fetchname := new.name;
return new;
end
$$;
create or replace function trigger_b()
returns trigger language plpgsql as $$
begin
new.postname := new.name;
return new;
end
$$;
create trigger trigger_a
create trigger trigger_b
before insert or update on tableFoo
for each row execute procedure trigger_a();
before insert or update on tableBar
for each row execute procedure trigger_b();
before insert or update on tableBaz
for each row execute procedure trigger_b();
运行上述操作会引发语法错误:
“创建”处或附近的语法错误
答案 0 :(得分:1)
这应该有效:
create or replace function trigger_a()
returns trigger language plpgsql as $$
begin
new.fetchname := new.name;
return new;
end
$$;
create or replace function trigger_b()
returns trigger language plpgsql as $$
begin
new.postname := new.name;
return new;
end
$$;
create trigger trigger_a
before insert or update on tableFoo
for each row execute procedure trigger_a();
create trigger trigger_b
before insert or update on tableBar
for each row execute procedure trigger_b();
create trigger trigger_b2
before insert or update on tableBaz
for each row execute procedure trigger_b();