Search code examples
postgresqlevent-triggers

Is it possible to capture DDL events against a specific set of tables with PostgreSQL's event triggers?


Can I restrict an event trigger to only capture events when DDL is performed against a specific set of tables?


Solution

  • I don't think you can avoid capturing the event, as the current CREATE EVENT TRIGGER statement only supports filtering by command tag.

    Once you're in the trigger function, you have access to a bit more information, so you could put something like this at the top:

    IF EXISTS (
        SELECT 1 FROM pg_event_trigger_ddl_commands()
        WHERE object_identity NOT IN ('myschema.mytable')
      )
    THEN
      RETURN;
    END IF;