| From: | Haritabh Gupta <haritabh1992(at)gmail(dot)com> |
|---|---|
| To: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Cc: | Florin Irion <irionr(at)gmail(dot)com>, Tim Waizenegger <tim(dot)waizenegger(at)enterprisedb(dot)com> |
| Subject: | Re: [PATCH] pg_get_domain_ddl: DDL reconstruction function for CREATE DOMAIN statement |
| Date: | 2026-02-18 23:50:16 |
| Message-ID: | 177145861697.626.9698606909114409697.pgcf@coridan.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Florin,
Thanks for addressing the comments. I tested v7 and found that
type modifiers (typmod) are lost in the base type output.
In build_create_domain_statement:
+ appendStringInfo(buf, "CREATE DOMAIN %s AS %s",
+ generate_qualified_type_name(typForm->oid),
+ generate_qualified_type_name(typForm->typbasetype));
generate_qualified_type_name does not include the type modifier,
so domains over types like varchar(N), numeric(P,S), char(N), bit(N),
time(N) etc. silently lose their modifiers. The generated DDL does not
roundtrip correctly.
create domain d1 as varchar(100);
select pg_get_domain_ddl('d1');
pg_get_domain_ddl
----------------------------------------------------------
CREATE DOMAIN public.d1 AS pg_catalog."varchar";
(1 row)
we should expect AS character varying(100).
Roundtrip confirms the semantic change:
```
select length(repeat('x', 150)::d1); -- returns 100 (truncated)
drop domain d1;
-- re-execute generated DDL
create domain public.d1 as pg_catalog."varchar";
select length(repeat('x', 150)::d1); -- returns 150 (not truncated)
```
Same issue with numeric(15,2): rounds to 2 decimals before roundtrip,
full precision after. Also confirmed with char(1), bit(8), time(3),
varbit(256).
I think for the base type we could use format_type_extended with
both FORMAT_TYPE_TYPEMOD_GIVEN and FORMAT_TYPE_FORCE_QUALIFY:
appendStringInfo(buf, "CREATE DOMAIN %s AS %s",
generate_qualified_type_name(typForm->oid),
format_type_extended(typForm->typbasetype,
typForm->typtypmod,
FORMAT_TYPE_TYPEMOD_GIVEN |
FORMAT_TYPE_FORCE_QUALIFY));
Regards,
Haritabh
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2026-02-19 00:10:19 | Re: [PATCH] pg_get_domain_ddl: DDL reconstruction function for CREATE DOMAIN statement |
| Previous Message | Tom Lane | 2026-02-18 23:42:37 | @remove-line-for-nolocal@ is dead code |