Re: pg_get__*_ddl consolidation

Andrew Dunstan <andrew@dunslane.net>

From: Andrew Dunstan <andrew@dunslane.net>
To: Mahendra Singh Thalor <mahi6run@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-03-19T21:30:06Z
Lists: pgsql-hackers
On 2026-03-19 Th 4:28 PM, Mahendra Singh Thalor wrote:
> On Fri, 20 Mar 2026 at 01:44, Andrew Dunstan <andrew@dunslane.net> wrote:
>>
>> You could construct these functions using plpgsql. The information isn't hidden from non-superusers. So what exactly would making these functions superuser-only achieve? Now it's true that the user might not be able to execute the DDL. But that's not the point.
> Thanks Andrew for the clarification.
>
> Sorry, my question might be stupid. Can we use these functions
> directly into our dump utilities so that common code can be removed
> and if there is any syntax change for a particular object, then no
> need to change into different-2 places, rather we just need to change
> it into ddlutils.c file only.


Well, we have tried to make the output like pg_dump. We might later 
provide options for more compact output. But it remains to be seen if it 
can be used in the pg_dump utilities. After all, it is going to produce 
output suitable for the source version, since there is no knowledge in 
the server of future versions. But pg_dump emits SQL suitable for the 
target version.

My original motivation was quite different. It was to give the user a 
piece of SQL that they could modify as they saw fit, rather than making 
them start with a blank canvas.


cheers


andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com




Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Use named boolean parameters for pg_get_*_ddl option arguments

  2. Convert ddlutils regression tests to TAP tests.

  3. Fix pfree crash in pg_get_role_ddl() and pg_get_database_ddl().

  4. Fixups for a4f774cf1c7

  5. Add infrastructure for pg_get_*_ddl functions

  6. Add pg_get_database_ddl() function

  7. Add pg_get_role_ddl() function

  8. Add pg_get_tablespace_ddl() function