multiple procedure call in a trigger?
Asked Answered
D

1

8

I would like to call multiple procedures from a trigger in postgres.

CREATE TRIGGER fn_trigger_notify_ev
AFTER INSERT
ON public.event_notifications
FOR EACH ROW
EXECUTE PROCEDURE public.notify_events();
EXECUTE PROCEDURE public.notify_events_count();

I have been getting error messages after executing this command so please let me know, is it possible to call multiple procedures in a trigger?

Error message:

ERROR:  syntax error at or near "public"
LINE 6:   EXECUTE PROCEDURE public.notify_events_count();
                        ^

********** Error **********

ERROR: syntax error at or near "public"
SQL state: 42601
Character: 167

Is there any method to call multiple procedures?

Dinh answered 5/1, 2019 at 8:13 Comment(1)
You need to create two triggers.Gaynellegayner
B
10

As commented, creating a trigger per procedure is one way. I think you could also just wrap the function calls to one procedure, like (psql example):

CREATE OR REPLACE FUNCTION do_notifies(
) RETURNS VOID AS $$
BEGIN
    PERFORM notify_events();
    PERFORM notify_events_count();
END; $$
LANGUAGE plpgsql;

and in your trigger just:

EXECUTE PROCEDURE public.do_notifies();
Bernstein answered 5/1, 2019 at 11:30 Comment(2)
Nice suggestion! 'Had to reformat the function call a little, but this seemed to work: PERFORM 'notify_events';Merrythought
I had to change void to trigger, otherwise this works well.Savitt

© 2022 - 2024 — McMap. All rights reserved.