Re: [PATCH] Add pg_get_trigger_ddl() to retrieve the CREATE TRIGGER statement

From: Philip Alger <paalger0(at)gmail(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Cary Huang <cary(dot)huang(at)highgo(dot)ca>, jian he <jian(dot)universality(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] Add pg_get_trigger_ddl() to retrieve the CREATE TRIGGER statement
Date: 2025-10-15 21:25:14
Message-ID: CAPXBC8+a_pENV6payEQxHEOkYG8O_JdfgOgZ_0qyVAUx3FXm4Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

Attachment Content-Type Size
v4-0001-Add-pg_get_trigger_ddl-function.patch application/octet-stream 12.6 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2025-10-15 21:38:05 Re: Clarification on Role Access Rights to Table Indexes
Previous Message Peter Smith 2025-10-15 21:17:30 Re: POC: enable logical decoding when wal_level = 'replica' without a server restart