diff --git a/drivers/trigger/queries.go b/drivers/trigger/queries.go index 8d2c495..c7a277d 100644 --- a/drivers/trigger/queries.go +++ b/drivers/trigger/queries.go @@ -109,6 +109,7 @@ func (d *Driver) getCreateTriggerSqlForOperation(listenerUid string, l *flash.Li } if rawConditionSql == "" { + statement = fmt.Sprintf(` CREATE OR REPLACE FUNCTION "%s"."%s"() RETURNS trigger AS $trigger$ BEGIN @@ -132,13 +133,17 @@ func (d *Driver) getCreateTriggerSqlForOperation(listenerUid string, l *flash.Li } if operation != "TRUNCATE" { + // Keep drop + create instead of 'create or replace' for Pgsql13 compatibility statement += fmt.Sprintf(` - CREATE OR REPLACE TRIGGER "%s" AFTER %s ON %s FOR EACH ROW EXECUTE PROCEDURE "%s"."%s"();`, - triggerName, operation, d.sanitizeTableName(l.Table), d.Config.Schema, triggerFnName) + DROP TRIGGER IF EXISTS "%s" ON %s; + CREATE TRIGGER "%s" AFTER %s ON %s FOR EACH ROW EXECUTE PROCEDURE "%s"."%s"();`, + triggerName, d.sanitizeTableName(l.Table), triggerName, operation, d.sanitizeTableName(l.Table), d.Config.Schema, triggerFnName) } else { + // Keep drop + create instead of 'create or replace' for Pgsql13 compatibility statement += fmt.Sprintf(` - CREATE OR REPLACE TRIGGER "%s" BEFORE TRUNCATE ON %s FOR EACH STATEMENT EXECUTE PROCEDURE "%s"."%s"();`, - triggerName, d.sanitizeTableName(l.Table), d.Config.Schema, triggerFnName) + DROP TRIGGER IF EXISTS "%s" ON %s; + CREATE TRIGGER "%s" BEFORE TRUNCATE ON %s FOR EACH STATEMENT EXECUTE PROCEDURE "%s"."%s"();`, + triggerName, d.sanitizeTableName(l.Table), triggerName, d.sanitizeTableName(l.Table), d.Config.Schema, triggerFnName) } return statement, eventName, nil