我有这样的代码:
create trigger audit_trigg_Test After insert on LOG
for each row when(new.j='PR' and new.ds='FB') execute procedure ABC()
when(new.j='PR' and new.ds='LNK') execute procedure XYZ()
create or replace function ABC() returns trigger as $$
begin
--Stuff
end
create or replace function XYZ() returns trigger as $$
begin
--Stuff
end
触发器应该基于条件
对存储过程起作用when(new.j='PR' and new.ds='FB') execute procedure ABC()
when(new.j='PR' and new.ds='LNK') execute procedure XYZ()
我该怎么做?
答案 0 :(得分:1)
为此,您需要定义两个单独的触发器:
CREATE TRIGGER audit_trigg_Test_ABC
AFTER INSERT ON log
FOR EACH ROW WHEN (NEW.j = 'PR' AND NEW.ds = 'FB') EXECUTE PROCEDURE ABC();
CREATE TRIGGER audit_trigg_Test_XYZ
AFTER INSERT ON log
FOR EACH ROW WHEN (NEW.j = 'PR' AND NEW.ds = 'LNK') EXECUTE PROCEDURE XYZ();
您可以使用WHEN
子句来确定是否触发了触发器,但您无法有条件地选择要调用的触发器函数。