[PATCH] Add pg_get_event_trigger_ddl() function

From: Ian Lawrence Barwick <barwick(at)gmail(dot)com>
To: PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: [PATCH] Add pg_get_event_trigger_ddl() function
Date: 2026-07-17 04:07:29
Message-ID: CAB8KJ=jAGYFYU77r2YPKxe_0MYjt529X-bKskLznigQFCrGimQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

Attachment Content-Type Size
v1-0001-Add-pg_get_event_trigger_ddl-function.patch application/octet-stream 9.4 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Smith 2026-07-17 04:10:44 A new C function `get_partition_root`.
Previous Message wenhui qiu 2026-07-17 04:03:17 Re: [PATCH] Refactor SLRU to always use long file names