[PATCH] Add pg_get_type_ddl() to retrieve the CREATE TYPE statement

From: Philip Alger <paalger0(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: [PATCH] Add pg_get_type_ddl() to retrieve the CREATE TYPE statement
Date: 2025-10-30 21:52:50
Message-ID: CAPXBC8J2-8GCaRgOf_LW3+Uk7nVUrQ8J1YxazaifX_kwpGiU3w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello Hackers,

I am submitting a patch as part of the Retail DDL functions project
described here [1]. This patch creates a function called pg_get_type_ddl
designed to retrieve the DDL statement for CREATE TYPE. Users can get the
DDL by providing a TYPE name like the following for the ENUM type:

SELECT pg_get_type_ddl('type_name_enum');

which gives you:

pg_get_type_ddl
------------------------------------------------------------
CREATE TYPE public.type_name_enum AS ENUM ('one', 'two', 'three');

I split up the types range, enum, shell, composite, and a base type into
different functions which support `pg_get_type_ddl`. Otherwise, the
function seemed too long.

This patch includes documentation, comments, and regression tests, all of
which have run successfully.

1.
https://www.postgresql.org/message-id/945db7c5-be75-45bf-b55b-cb1e56f2e3e9%40dunslane.net

--
Best,
Phil Alger

Attachment Content-Type Size
v1-0001-Add-pg_get_type_ddl-function.patch application/octet-stream 33.7 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2025-10-30 21:59:32 Re: POC: enable logical decoding when wal_level = 'replica' without a server restart
Previous Message Jon Jenkins 2025-10-30 21:40:14 Potential bug introduced in PG17 with query parallelization - plan flip