单个语句中的多个触发器 declarations/assignments
Multiple Trigger declarations/assignments in a single statement
我想声明几个触发器并在 单个脚本.
中将它们分配给多个表
示例:
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();
运行 以上抛出语法错误:
syntax error at or near "create"
这应该有效:
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();
我想声明几个触发器并在 单个脚本.
中将它们分配给多个表示例:
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();
运行 以上抛出语法错误:
syntax error at or near "create"
这应该有效:
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();