Re: [PATCH] pg_get_domain_ddl: DDL reconstruction function for CREATE DOMAIN statement

From: Florin Irion <irionr(at)gmail(dot)com>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, Neil Chen <carpenter(dot)nail(dot)cz(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: [PATCH] pg_get_domain_ddl: DDL reconstruction function for CREATE DOMAIN statement
Date: 2025-12-02 21:11:39
Message-ID: 5dbba701-c93b-4625-b35b-76d52131535e@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Hello,

On 20/11/25 07:55, Man Zeng wrote:
> Quick correction with an apology: I accidentally created a new thread (https://www.postgresql.org/message-id/tencent_64301BB7627E58CD256CE15F%40qq.com) and submitted the patch there—my apologies for the mix-up! Let’s just continue the discussion here as planned.
On 20/11/25 09:47, Chao Li wrote:
> 1. The error message "cache lookup failed for type 0” looks not good. At lease saying something like “domain ‘int’ does not exist”.
>
> 2. I created a domain “int” in “public”, as you see, “public” is in the search_path, but SELECT pg_get_domain_ddl('int’); failed.

Thank you both Man Zeng and Chao Li for checking this. Changes added in v5.
I don't think there is a way to make the path issue work, so we just
give more info
to the caller. We exit with error when a built-in name is used and we
throw also a
hint saying that schema-qualified domain name should be used to be sure
it's not
conflicting with a built in  name.

On 20/11/25 10:44, Neil Chen wrote:
> Hi Florin,
>
> +pg_get_domain_ddl_ext(PG_FUNCTION_ARGS)
> +{
> + Oid domain_oid = PG_GETARG_OID(0);
> + bool pretty = PG_GETARG_BOOL(1);
> + char   *res;
> + int prettyFlags;
> +
> + prettyFlags = pretty ? GET_PRETTY_FLAGS(pretty) : 0;
>
>
> Seems like we should directly use GET_PRETTY_FLAGS here, as it already
> checks the value of "pretty". For a "display-oriented" result, using
> PRETTYFLAG_INDENT looks more appropriate.

Well, actually no,
GET_PRETTY_FLAGS(false) returns PRETTYFLAG_INDENT
But we actually want 0 when pretty is false (no indentation, just spaces)

> + appendStringInfo(buf, "CREATE DOMAIN %s AS %s",
> + generate_qualified_type_name(typForm->oid),
> + generate_qualified_type_name(typForm->typbasetype));
>
>
> It might be good to first call get_typtype to check if it is
> TYPTYPE_DOMAIN.

I added this in `pg_get_domain_ddl_worker`, as we need to make this
check ASAP.

Cheers,
Florin Irion
Tim Waizenegger
EDB (EnterpriseDB)

Attachment Content-Type Size
v5-0001-Add-pg_get_domain_ddl-function-to-reconstruct-CRE.patch text/plain 41.7 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2025-12-02 22:00:51 pgindent versus struct members and typedefs
Previous Message Sami Imseih 2025-12-02 20:58:32 Re: [Proposal] Adding callback support for custom statistics kinds