| From: | Jim Jones <jim(dot)jones(at)uni-muenster(dot)de> |
|---|---|
| To: | "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Cc: | Matheus Alcantara <matheusssilv97(at)gmail(dot)com> |
| Subject: | COMMENTS are not being copied in CREATE TABLE LIKE |
| Date: | 2026-02-12 10:11:58 |
| Message-ID: | e08cb97f-0364-4002-9cda-3c16b42e4136@uni-muenster.de |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
While reviewing another patch[1] I saw that COMMENTS on tables are being
ignored in CREATE TABLE LIKE:
psql (18.1 (Debian 18.1-1.pgdg13+2))
Type "help" for help.
postgres=# \pset null '(null)'
Null display is "(null)".
postgres=# CREATE TABLE t1 (id int, name text);
COMMENT ON TABLE t1 IS 'table comment';
CREATE TABLE t2 (LIKE t1 INCLUDING ALL);
CREATE TABLE t3 (LIKE t1 INCLUDING COMMENTS);
SELECT
obj_description('t1'::regclass, 'pg_class') AS t1_comment,
obj_description('t2'::regclass, 'pg_class') AS t2_comment,
obj_description('t3'::regclass, 'pg_class') AS t3_comment;
CREATE TABLE
COMMENT
CREATE TABLE
CREATE TABLE
t1_comment | t2_comment | t3_comment
---------------+------------+------------
table comment | (null) | (null)
(1 row)
v1 attached attempts to fix it by expanding expandTableLikeClause() to
retrieve and copy the table-level comment when the INCLUDING COMMENTS
[ALL] option is specified:
psql (19devel)
Type "help" for help.
postgres=# CREATE TABLE t1 (id int, name text);
COMMENT ON TABLE t1 IS 'table comment';
CREATE TABLE t2 (LIKE t1 INCLUDING ALL);
CREATE TABLE t3 (LIKE t1 INCLUDING COMMENTS);
SELECT
obj_description('t1'::regclass, 'pg_class') AS t1_comment,
obj_description('t2'::regclass, 'pg_class') AS t2_comment,
obj_description('t3'::regclass, 'pg_class') AS t3_comment;
CREATE TABLE
COMMENT
CREATE TABLE
CREATE TABLE
t1_comment | t2_comment | t3_comment
---------------+---------------+---------------
table comment | table comment | table comment
(1 row)
Thoughts?
Best, Jim
1 -
https://www.postgresql.org/message-id/flat/DG7Y34A6VBEG.76L7K1OML5DI%40gmail.com
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Fix-missing-table-level-comment-copying-in-CREATE.patch | text/x-patch | 5.2 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Bertrand Drouvot | 2026-02-12 10:15:06 | Replace literal 0 values with the appropriate Invalid* constants |
| Previous Message | Florin Irion | 2026-02-12 10:11:55 | Re: [PATCH] pg_get_domain_ddl: DDL reconstruction function for CREATE DOMAIN statement |