Create or replace trigger postgres

后端 未结 5 642
情话喂你
情话喂你 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:46

    you can use below code.

    DO $$ BEGIN
    
    CREATE (trigger, type , ...);
    
    EXCEPTION
      WHEN others THEN null;
    END $$;
    

    sample:

    DO $$ BEGIN
    
    CREATE TRIGGER trigger_workIDExist
      BEFORE INSERT OR UPDATE ON "GalleryModel"
      FOR EACH ROW EXECUTE PROCEDURE check_workIDExist();
    
    EXCEPTION
      WHEN others THEN null;
    END $$;
    

提交回复
热议问题