Monthly Summary: pg_get_trigger_ddl() and pg_get_policy_ddl() — May 2026
Overview
This thread encompasses two intertwined sub-patches under Andrew Dunstan's Retail DDL Functions project, which aims to expose per-object DDL reconstruction as first-class SQL-callable functions (beyond pg_dump). May 2026 saw continued technical debate on identifier semantics, a major API redesign for the policy DDL function, and several correctness fixes.
Key Developments
1. Identifier Parsing Tension for Trigger Names
The most substantive unresolved dispute concerns how pg_get_trigger_ddl(regclass, name) handles its second argument (trigger name as text):
- v5 used
textToQualifiedNameList()to apply SQL identifier rules (downcase unquoted, strip quotes from quoted names), following Jim Jones's consistency argument withregclassbehavior. - Soumya Murali's late feedback (May 2026) identified a regression: names with special characters like
"Weird-Trigger!"break under identifier parsing. She proposed reverting to raw-text matching. - This remains contested — either choice surprises some users due to the fundamental tension between identifier semantics and string semantics.
2. pg_get_policy_ddl() Adopts VARIADIC Options API
Akshay Joshi substantially reworked the policy DDL function to use the VARIADIC options pattern established by the recently committed pg_get_database_ddl():
pg_get_policy_ddl(table regclass, policy_name name, VARIADIC options text[]) RETURNS setof text
This replaces the earlier (regclass, name, bool pretty) signature. The change supersedes the GET_DDL_PRETTY_FLAGS macro approach, with pretty-printing now gated through key-value option pairs (e.g., 'pretty', 'true'). The return type changed to setof text (returning empty set for NULL inputs rather than NULL).
3. Double-Parenthesization Bug Fixed (v3)
Japinli identified that pg_get_expr() output already includes parentheses, so the format string "USING (%s)" produced USING ((expr)). Akshay's v3 patch (2026-05-25) fixes this for both USING and WITH CHECK clauses.
4. Code Organization: ddlutils.c
Philip noted that these DDL functions "now live in ddlutils.c" — a new module splitting DDL-generation functions away from ruleutils.c. This signals the Retail DDL project is being consolidated into its own subsystem.
Accepted Design Decisions
| Decision | Resolution | Authority |
|---|---|---|
Use regclass (not name) for table argument |
Accepted | Álvaro Herrera (committer) |
New function pg_get_trigger_ddl vs overloading pg_get_triggerdef |
New function | Andrew Dunstan (project originator) |
| Return NULL for invalid OID in trigger DDL | Accepted | Jian He, following pg_basetype precedent |
| Explicit error for schema-qualified trigger name | Accepted | Philip (challenged by Jim Jones) |
| VARIADIC options API for policy DDL | Accepted | Akshay Joshi, following pg_get_database_ddl() |
| Trailing semicolon in DDL output | Accepted | Philip |
Unresolved Issues
- Trigger name identifier parsing: Soumya's feedback may force a revert to raw-text, reopening Jim's original consistency objection.
pg_get_exprlimitations for policies: Policy quals can contain subqueries, whichpg_get_exprcannot handle. A dedicated deparser may be needed.- Permission checks: Whether ACL checks should gate DDL retrieval remains open for the broader project.
- Pretty-printing for triggers: Philip is still developing a
_worker_formattedapproach to avoid breaking psql's\doutput.