gpt4 book ai didi

sql - postgres根据条件执行存储过程

转载 作者:行者123 更新时间:2023-11-29 13:27:04 25 4
gpt4 key购买 nike

我有这样的代码:

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()

我该怎么做?

最佳答案

为此,您需要定义两个单独的触发器:

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 子句来确定触发器是否被触发,但您不能有条件地选择要调用的触发器函数。

关于sql - postgres根据条件执行存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31848084/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com