Create or replace trigger postgres Create or replace trigger postgres postgresql postgresql

Create or replace trigger postgres


No way to create or replace a trigger but can do this way

DROP TRIGGER IF EXISTS yourtrigger_name on "yourschemaname"."yourtablename";


Postgresql has transaction DDL so BEGIN > DROP > CREATE > COMMIT is the equivalent of CREATE OR REPLACE

This is a nice write-up of how postgre's transactional DDL compares to other systems (such as oracle)

Current postgres planned features regarding triggers do not include adding the REPLACE syntax.


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();