Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple procedure call in a trigger?

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?

like image 279
MjM Avatar asked Jan 05 '19 08:01

MjM


1 Answers

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();
like image 65
pirho Avatar answered Oct 19 '22 02:10

pirho