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

From: Quan Zongliang <quanzongliang(at)yeah(dot)net>
To: Philip Alger <paalger0(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] Add pg_get_type_ddl() to retrieve the CREATE TYPE statement
Date: 2025-10-31 00:54:30
Message-ID: 1ad1aba9-9619-48b3-9100-b2fea5d0fa9a@yeah.net
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 10/31/25 5:52 AM, Philip Alger wrote:
> 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');
>
Such functions are conventionally called xxxdef. For example:
pg_get_ruledef
pg_get_typedef
pg_get_indexdef

So I think its name should be called: pg_get_typedef

Furthermore, it would be even more beneficial if the parameter type
could support the Oid type (rather than merely supporting the text
type). This is also done to conform to the definition of similar functions.

--
Regards,
Quan Zongliang

> 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 <https://www.postgresql.org/message-
> id/945db7c5-be75-45bf-b55b-cb1e56f2e3e9%40dunslane.net>
>
> --
> Best,
> Phil Alger

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Philip Alger 2025-10-31 01:34:48 Re: [PATCH] Add pg_get_type_ddl() to retrieve the CREATE TYPE statement
Previous Message Michael Paquier 2025-10-31 00:48:48 Re: Improved TAP tests by replacing sub-optimal uses of ok() with better Test::More functions