 AS $$
   BEGIN
     DROP EVENT TRIGGER IF EXISTS link_ghost_tables;
+    DROP TRIGGER IF EXISTS check_ddl_update ON cartodb.cdb_ddl_execution;
   END;
 $$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE;

AS $$
  BEGIN
    DROP EVENT TRIGGER IF EXISTS link_ghost_tables;
    CREATE EVENT TRIGGER link_ghost_tables
    ON ddl_command_end
    WHEN TAG IN ('CREATE TABLE', 'SELECT INTO', 'DROP TABLE', 'ALTER TABLE', 'CREATE TRIGGER', 'DROP TRIGGER', 'CREATE VIEW', 'DROP VIEW', 'ALTER VIEW')

  END;
$$ LANGUAGE plpgsql VOLATILE PARALLEL UNSAFE SECURITY DEFINER;

-- Event trigger to save the current transaction in cartodb.cdb_ddl_execution
CREATE OR REPLACE FUNCTION CDB_SaveDDLTransaction()
RETURNS event_trigger
