Re: COMMENTS are not being copied in CREATE TABLE LIKE

From: Carlos Alves <carlos(at)alves(dot)inf(dot)br>
To: Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, Matheus Alcantara <matheusssilv97(at)gmail(dot)com>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Subject: Re: COMMENTS are not being copied in CREATE TABLE LIKE
Date: 2026-03-24 18:32:21
Message-ID: CAL-Pge4eWCAu7VcjXhXxFKPwT0jYqG2xG7vRAyZJXcr75voJCA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Em seg., 23 de mar. de 2026 às 16:40, Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
escreveu:

>
>
> On 13/02/2026 10:19, Jim Jones wrote:
> > ...
> > Example:
> >
> > CREATE TABLE t1 (a int);
> > COMMENT ON TABLE t1 IS 'comment from table 1';
> > CREATE TABLE t2 (b int);
> > COMMENT ON TABLE t2 IS 'comment from table 2';
> > CREATE TABLE t3 (c int);
> > COMMENT ON TABLE t3 IS 'comment from table 3';
> >
> > CREATE TABLE tm (
> > LIKE t1 INCLUDING COMMENTS,
> > LIKE t3 INCLUDING COMMENTS,
> > LIKE t2 INCLUDING COMMENTS
> > );
> >
> > SELECT obj_description('tm'::regclass, 'pg_class') AS table_comment;
> > table_comment
> > ----------------------
> > comment from table 1+
> > comment from table 3+
> > comment from table 2
> > (1 row)
> >
> >
> > Any thoughts on that?
>
> Rebase
>
> Best, Jim

Hi Jim!

I ran some tests after applying your patch and initially didn't find any
problems. I tried to cover the main scenarios in a focused way, observing
the generated results.

Regarding the possibility of including comments in the table itself using
the LIKE clause, it seems sensible since other elements like columns,
indexes, and constraints have copied comments, as already discussed in the
thread.

Just one point I'd like to address is the documentation. Following the idea
of the other "includings" options wouldn't it be interesting to present a
more concise text? As a suggestion, it could be something like:

"Comments on columns, not null and check constraints, indexes, extended
statistics and the table itself from a source table will be copied. If the
command references multiple source tables with including clauses, any
existing table-level comments will be merged into a single entry, separated
by newlines in the order they were specified."

I've attached some preliminary tests I performed.

Thank you in advance for your attention.

Attachment Content-Type Size
tests.sql application/octet-stream 8.2 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2026-03-24 18:41:24 Re: Initial COPY of Logical Replication is too slow
Previous Message Greg Burd 2026-03-24 18:02:07 Re: Expanding HOT updates for expression and partial indexes