| From: | Philip Alger <paalger0(at)gmail(dot)com> |
|---|---|
| To: | Chao Li <li(dot)evan(dot)chao(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-11-01 17:44:47 |
| Message-ID: | CAPXBC8LDGT6Ptf4GJh57My439BfC2gNY8ATn_fszfDUs7xTApQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Chao,
Appreciate you pulling it apart:
> 1
> 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.
>
Yeah, I changed that to `true`, so it should handle correctly now - v3. But
not sure how you got "it would “ereport” inside LookupTypeName()". I don't
see where ereport would happen inside `LookupTypeNameExtended`. It seems
like it would hit here and return NULL:
if (!OidIsValid(typoid))
{
if (typmod_p)
*typmod_p = -1;
return NULL;
}
> 2
> 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)
>
I added that test to make sure it provides no output.
3. As discussed in other get_xxx_ddl() patches, does this function needs a
> pretty flag? I think other patches have that.
>
I see three functions that a couple people posted that use it; however, for
pg_get_policy_ddl is the only one using it to format the code. I am not
sure there is consensus on how SQL should be formatted.
--
Best,
Phil Alger
| Attachment | Content-Type | Size |
|---|---|---|
| v3-0001-Add-pg_get_type_ddl-function.patch | application/octet-stream | 39.5 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2025-11-01 18:03:16 | Re: Unused variable in perl test |
| Previous Message | Tom Lane | 2025-11-01 17:04:36 | Re: [PATCH] Fix LTREE subpath with negative offset |