Can an event trigger capture DDL events of dropping objects?
Event triggers are global to a particular database and are capable of capturing DDL events occured in the database. Redrock Postgres supports capturing events of dropping objects at the end of a command (corresponding to the
In the example below, we create an event trigger that captures DDL events that occur in the database at the end of a command.
CREATE OR REPLACE FUNCTION ddl_trigger_func() RETURNS event_trigger AS $$ DECLARE obj record; BEGIN FOR obj IN SELECT * FROM pg_event_trigger_ddl_commands() LOOP RAISE NOTICE 'ddl command: %', pg_ddl_command_deparse(obj.command); END LOOP; END $$ LANGUAGE plpgsql; CREATE EVENT TRIGGER ddl_event_trigger ON ddl_command_end EXECUTE PROCEDURE ddl_trigger_func(); CREATE TABLE t_table (id integer, name text); DROP TABLE t_table;
In the example above, we will find that when the table
t_table is dropped, the event trigger captures the corresponding DDL event.