Skip to content

Instantly share code, notes, and snippets.

@michelp
Created May 11, 2020 23:25
Show Gist options
  • Save michelp/c6daa1c123c4743be4f8b08fad5d5396 to your computer and use it in GitHub Desktop.
Save michelp/c6daa1c123c4743be4f8b08fad5d5396 to your computer and use it in GitHub Desktop.
drop event trigger ddl_event_trigger_trigger;
drop event trigger test_event_trigger_for_drops;
drop event trigger test_table_rewrite_oid;
CREATE OR REPLACE FUNCTION test_event_trigger_ddl()
RETURNS event_trigger AS $$
DECLARE obj record;
BEGIN
FOR obj IN SELECT * FROM pg_event_trigger_ddl_commands()
LOOP
RAISE NOTICE '% created object: % % %',
tg_tag,
obj.object_type,
obj.schema_name,
obj.object_identity;
END LOOP;
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION test_event_trigger_for_drops()
RETURNS event_trigger LANGUAGE plpgsql AS $$
DECLARE
obj record;
BEGIN
FOR obj IN SELECT * FROM pg_event_trigger_dropped_objects()
LOOP
RAISE NOTICE '% dropped object: % %.% %',
tg_tag,
obj.object_type,
obj.schema_name,
obj.object_name,
obj.object_identity;
END LOOP;
END
$$;
CREATE EVENT TRIGGER test_event_trigger_for_drops
ON sql_drop
EXECUTE FUNCTION test_event_trigger_for_drops();
CREATE EVENT TRIGGER ddl_event_trigger_trigger
ON ddl_command_end
EXECUTE PROCEDURE test_event_trigger_ddl();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment