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

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Philip Alger <paalger0(at)gmail(dot)com>
Cc: Quan Zongliang <quanzongliang(at)yeah(dot)net>, 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 23:09:24
Message-ID: 581DFE68-6E53-4B4B-8B4C-02AB06731EF8@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Nov 1, 2025, at 06:29, Philip Alger <paalger0(at)gmail(dot)com> wrote:
>
>
> <v2-0001-Add-pg_get_type_ddl-function.patch>

1
```
+ /*
+ * Look up the type tuple to allow shell types.
+ */
+ typeTup = LookupTypeName(NULL, typeStruct, NULL, false);
+ if (typeTup == NULL)
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("type \"%s\" does not exist",
+ TypeNameToString(typeStruct))));
```

Here when you call LookupTypeName(), you give the last parameter “missing_ok” a value of “false”, so that it would “ereport” inside LookupTypeName(), so your manual check of “if (typeTup == NULL)” will never be satisfied.

2
```
+{ oid => '8414', descr => 'get CREATE statement for type',
+ proname => 'pg_get_type_ddl', prorettype => 'text', proisstrict => 't',
+ proargtypes => 'text', proargnames => '{typname}',
+ prosrc => 'pg_get_type_ddl' },
```
Here you set proisstrict => ’t’. With strict mode, the function will not be executed if any of input arguments are NULL.

So add this test seems meaningless, because the function is not executed at all.
```
+SELECT pg_get_type_ddl(NULL);
+ pg_get_type_ddl
+-----------------
+
+(1 row)
```

3. As discussed in other get_xxx_ddl() patches, does this function needs a pretty flag? I think other patches have that.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Xuneng Zhou 2025-11-01 00:41:33 Re: Question on pg_stat_io showing zero reads/writes for I/O workers
Previous Message Jacob Champion 2025-10-31 22:54:28 Re: Updating IPC::Run in CI?