7

Is there a method for creating a trigger and trigger function in a single query...

 3 years ago
source link: https://www.codesd.com/item/is-there-a-method-for-creating-a-trigger-and-trigger-function-in-a-single-query-in-postgresql.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Is there a method for creating a trigger and trigger function in a single query in PostgreSQL

advertisements

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.


Thank you for all your answers but finally I have found the answer, I just removed this script from my query.

  NOT LEAKPROOF
  COST 100.0

that 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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK