Re: COMMENTS are not being copied in CREATE TABLE LIKE - Mailing list pgsql-hackers

From Jim Jones
Subject Re: COMMENTS are not being copied in CREATE TABLE LIKE
Date
Msg-id 5888209c-44b5-438a-abd3-7d07990b3a4c@uni-muenster.de
Whole thread Raw
In response to Re: COMMENTS are not being copied in CREATE TABLE LIKE  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: COMMENTS are not being copied in CREATE TABLE LIKE
Re: COMMENTS are not being copied in CREATE TABLE LIKE
List pgsql-hackers
Thanks everyone for the comments!

On 13/02/2026 05:30, Tom Lane wrote:
> Chao Li <li.evan.chao@gmail.com> writes:
>> I feel the current behavior is proper. When you create a table using
>> LIKE, you are cloning the structure, not the identity.

The concern regarding identity is certainly a valid one, but in this
case I do not see how it applies. Copying the comment would not, IMHO,
transfer the identity of the source table (in a semantic sense), but
would instead merely indicate its provenance.

> Yeah, I was about to make a similar comment.  We do not for example
> clone the ownership or permissions of the source table.  Maybe there
> is an argument for cloning the table-level comment but it's by no
> means open-and-shut.  So I think the current behavior is intentional
> not an oversight.  Might be good to go find the thread in which the
> INCLUDING COMMENTS functionality was developed and see if there was
> discussion.

I did a bit of digging in the mailing list and found this old thread[1]
where INCLUDING COMMENTS was introduced. I couldn't see anything related
to table-level comments there. Perhaps it was discussed elsewhere?

On 13/02/2026 05:13, Fujii Masao wrote:
> For example, if two source tables each have a table comment and both are
> specified in LIKE, which comment should be applied to the new table?

On 13/02/2026 05:22, David G. Johnston wrote:
> Both, with a new line between them.

I supposed we could, as David mentioned, simply concatenate them. How it
should be done can be discussed, but a \n (or two) would IMO work just fine.

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?

Best, Jim

1 -
https://www.postgresql.org/message-id/flat/20090907114058.C855.52131E4D%40oss.ntt.co.jp
Attachment

pgsql-hackers by date:

Previous
From: Srirama Kucherlapati
Date:
Subject: RE: AIX support
Next
From: Andreas Karlsson
Date:
Subject: Re: Our ABI diff infrastructure ignores enum SysCacheIdentifier