1

I have a code like this :

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

The trigger should work on stored procedures based on the conditions

when(new.j='PR' and new.ds='FB') execute procedure ABC()
         when(new.j='PR' and new.ds='LNK')  execute procedure XYZ()

How can I do this?

1 Answer 1

1

For this you need to define two separate triggers:

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

You can use the WHEN clause to determine if a trigger is fired, but you cannot conditionally select a trigger function to call.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.