Create or replace trigger postgres

后端 未结 5 737
情话喂你
情话喂你 2021-02-02 05:01

I want to \"create or replace\" a trigger for a postgres table. However, there is not such sql expression.

I see that I can do a \"DROP TRIGGER IF EXISTS\"

5条回答
  •  情书的邮戳
    2021-02-02 05:30

    You should use two statements: one for drop trigger and another for creating a trigger.

    Example:

    DROP TRIGGER IF EXISTS my_trigger
      ON my_schema.my_table;
    CREATE TRIGGER my_trigger
      BEFORE INSERT OR UPDATE
      ON my_schema.my_table
      FOR EACH ROW EXECUTE PROCEDURE my_schema.my_function();
    

提交回复
热议问题