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

From: Philip Alger <paalger0(at)gmail(dot)com>
To: Josef Šimánek <josef(dot)simanek(at)gmail(dot)com>
Cc: Josef Šimánek <retro(at)ballgag(dot)cz>, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, jian he <jian(dot)universality(at)gmail(dot)com>, Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Cary Huang <cary(dot)huang(at)highgo(dot)ca>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] Add pg_get_trigger_ddl() to retrieve the CREATE TRIGGER statement
Date: 2025-11-07 22:06:59
Message-ID: CAPXBC8++u+mYVDMDAeJ=KYPWYbOdonL-7jJOE31U1j4F6W35vg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello Hackers,

I was thinking about the patch a little more, and I think some people may
want the pretty formatted option.

I was going to create another patch for pg_get_triggerdef to add that
functionality, like pg_get_functiondef and pg_get_viewdef. but I think it
will break it since pg_get_triggerdef is used for the \d table command and
requires the trigger to be printed as one line. The idea I had was to
create another function called pg_get_triggerdef_worker_formatted(oid) that
takes the OID and behaves the same way as pg_get_triggerdef_worker but adds
the pretty formatting capability using appendContextKeyword() and the
PRETTYFLAG_INDENT.

You might be saying, "there already is a pretty printing capability for
pg_get_triggerdef". No, it just removes the schema name. What I
am proposing is similar to the output of pg_get_functiondef or
pg_get_viewdef. The proposal is this, I can add the
pg_get_triggerdef_worker_formatted function and refactor pg_get_trigger_ddl
so that we get a formatted output like this:

CREATE TRIGGER trg BEFORE INSERT
ON main_table
FOR EACH STATEMENT
EXECUTE FUNCTION trgf()

versus one line:

CREATE TRIGGER trg BEFORE INSERT ON main_table FOR EACH STATEMENT EXECUTE
FUNCTION trgf();

The function pg_get_triggerdef_worker_formatted will receive an OID as a
parameter, while pg_get_trigger_ddl will remain the same taking the
regclass and trigger name as parameters.

The other proposal is to leave it as it is.

--
Best,
Phil Alger
EDB: https://www.enterprisedb.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Corey Huinker 2025-11-07 22:28:50 Re: Extended Statistics set/restore/clear functions.
Previous Message Alexander Korotkov 2025-11-07 22:02:36 Re: Implement waiting for wal lsn replay: reloaded