Hi Attached is a patch implementing a function to generate the DDL for a CREATE EVENT TRIGGER statement. This complements existing similar functions (pg_get_database_ddl(), pg_get_role_ddl() etc.).
Patch includes regression test and documentation.
Example:
CREATE OR REPLACE FUNCTION forbid_table_rewrites()
RETURNS event_trigger
LANGUAGE plpgsql
AS $$
BEGIN
RAISE EXCEPTION 'command % prohibited', tg_tag;
END;
$$;
CREATE EVENT TRIGGER forbid_rewrites
ON table_rewrite
WHEN tag IN ('ALTER TABLE', 'ALTER MATERIALIZED VIEW')
EXECUTE FUNCTION forbid_table_rewrites();
SELECT pg_get_event_trigger_ddl('forbid_rewrites');
postgres=# SELECT pg_get_event_trigger_ddl('forbid_rewrites',true);
pg_get_event_trigger_ddl
------------------------------------------------------------
CREATE EVENT TRIGGER forbid_rewrites +
ON table_rewrite +
WHEN TAG IN ('ALTER TABLE', 'ALTER MATERIALIZED VIEW')+
EXECUTE FUNCTION public.forbid_table_rewrites();
(1 row)
Regards
Ian Barwick
v1-0001-Add-pg_get_event_trigger_ddl-function.patch
Description: Binary data
