Re: [PATCH] Add pg_get_trigger_ddl() to retrieve the CREATE TRIGGER statement
Philip Alger <paalger0@gmail.com>
From: Philip Alger <paalger0@gmail.com>
To: Andrew Dunstan <andrew@dunslane.net>
Cc: Cary Huang <cary.huang@highgo.ca>, jian he <jian.universality@gmail.com>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2025-10-15T21:25:14Z
Lists: pgsql-hackers
Attachments
- v4-0001-Add-pg_get_trigger_ddl-function.patch (application/octet-stream) patch v4-0001
Thank you Andrew.
I think you should change the documentation.
>
Changed.
I've updated v4, attached here. One thing I noted while testing was that
pg_get_triggerdef does not put the statement terminator (;) at the end of
the printed statement.
pg_get_triggerdef
----------------------------------------------------------------------------------------------------------------------------------------------------
CREATE TRIGGER modified_a BEFORE UPDATE OF a ON public.main_table FOR EACH
ROW WHEN ((old.a <> new.a)) EXECUTE FUNCTION trigger_func('modified_a')
(1 row)
I accounted for that in v4.
SELECT pg_get_trigger_ddl('main_table', 'modified_a');
pg_get_trigger_ddl
-----------------------------------------------------------------------------------------------------------------------------------------------------
CREATE TRIGGER modified_a BEFORE UPDATE OF a ON public.main_table FOR EACH
ROW WHEN ((old.a <> new.a)) EXECUTE FUNCTION trigger_func('modified_a');
(1 row)
--
Best,
Phil Alger