Home:ALL Converter>Is there any method to create trigger and trigger function in a single query in PostgreSQL

Is there any method to create trigger and trigger function in a single query in PostgreSQL

Ask Time:2017-06-22T11:27:01         Author:xxx secret

Json Formatter

I have a problem with PostgreSQL. I want to create a trigger and trigger function in a single query, so I can make trigger in a faster way. this is my trigger function:

    CREATE FUNCTION public.tda_a1()
      RETURNS trigger
      LANGUAGE 'plpgsql'
      COST 100.0
      VOLATILE NOT LEAKPROOF 
      COST 100.0
    AS $BODY$
    BEGIN
      DELETE FROM ref_dati2 where kd_propinsi = OLD.kd_propinsi;
      RETURN OLD;
    END;
    $BODY$;

And this is the trigger :

    CREATE TRIGGER tda_a1
      BEFORE DELETE
      ON public.ref_propinsi
      FOR EACH ROW
      EXECUTE PROCEDURE public.tda_a1();

I have tried to join those into a single query but failed. Maybe someone can help me.

Author:xxx secret,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/44689633/is-there-any-method-to-create-trigger-and-trigger-function-in-a-single-query-in
xxx secret :

Thank you for all your answers but finally I have found the answer,\nI just removed this script from my query.\n\n NOT LEAKPROOF \n COST 100.0\n\n\nthat is the default from pgadmin, when I removed it I can run trigger an trigger function in a single query as many as I want",
2017-06-23T04:05:54
yy