| From: | ZizhuanLiu X-MAN <44973863(at)qq(dot)com> |
|---|---|
| To: | Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>, matheusssilv97 <matheusssilv97(at)gmail(dot)com>, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, masao(dot)fujii <masao(dot)fujii(at)gmail(dot)com>, david(dot)g(dot)johnston <david(dot)g(dot)johnston(at)gmail(dot)com>, tgl <tgl(at)sss(dot)pgh(dot)pa(dot)us>, huseyin(dot)d3r <huseyin(dot)d3r(at)gmail(dot)com> |
| Cc: | pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, 我自己的邮箱 <44973863(at)qq(dot)com> |
| Subject: | Re: COMMENTS are not being copied in CREATE TABLE LIKE |
| Date: | 2026-07-24 02:01:12 |
| Message-ID: | tencent_28945AA8110B3EA5AD8A366542E61BCA5205@qq.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
>Original
>From: Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
>Date: 2026-07-23 19:51
>To: ZizhuanLiu X-MAN <44973863(at)qq(dot)com>, matheusssilv97 <matheusssilv97(at)gmail(dot)com>, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, masao.fujii <masao(dot)fujii(at)gmail(dot)com>, david.g.johnston <david(dot)g(dot)johnston(at)gmail(dot)com>, tgl <tgl(at)sss(dot)pgh(dot)pa(dot)us>, huseyin.d3r <huseyin(dot)d3r(at)gmail(dot)com>
>Cc: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
>Subject: Re: COMMENTS are not being copied in CREATE TABLE LIKE
>These are good points, but I'd argue that excluding multiple tables from
>this feature would be hard to justify. Some of these points can be made
>to column comments as well -- we cannot guarantee their semantics in the
>new table, and yet we allow them to be copied.
>
>postgres=# CREATE TABLE t1 (a int);
>COMMENT ON COLUMN t1.a IS 'foo';
>CREATE TABLE t2 (b int);
>COMMENT ON COLUMN t2.b IS 'bar';
>
>CREATE TABLE tm (
> LIKE t1 INCLUDING COMMENTS,
> LIKE t2 INCLUDING COMMENTS
>);
>CREATE TABLE
>COMMENT
>CREATE TABLE
>COMMENT
>CREATE TABLE
>postgres=# SELECT
> col_description('tm'::regclass::oid, 1),
> col_description('tm'::regclass::oid, 2);
> col_description | col_description
>-----------------+-----------------
> foo | bar
>(1 row)
>
>In this case is up to user to either make sure the column comments are
>"transferable" or to correct them in the target table -- which is also
>my case on including the table comments.
>
>I'm not totally against dropping comments for multiple tables, but I
>want to make sure our arguments against having them make sense. If we
>conclude that it's impractical to concatenate table comments we should
>also consider the option of withdrawing the patch -- it's not like I'm
>terribly in love with it :)
>
>Thanks for the input!
>
>Best, Jim
Hi, Jim, everyone
Thanks for all your feedback, discussion and reminders.
After further consideration, I would like to clarify that I am only sharing my
personal perspective here, with no intention of pushing for any specific
implementation or insisting on my preference.
I have reviewed the relevant syntax and parsing rules:
```SQL
{ INCLUDING | EXCLUDING }
{ COMMENTS | COMPRESSION | CONSTRAINTS | DEFAULTS | GENERATED | IDENTITY | INDEXES | STATISTICS | STORAGE | ALL }
```SQL
With the existing implementation, any object enabled via these clauses is
copied strictly one-to-one alongside the source objects. The command never
performs additional logic such as merging content or pruning items automatically.
This leaves three general user workflows for any single attribute type XXX:
1. All instances of XXX fit the use case perfectly: use `INCLUDING XXX` with no post-copy modifications required.
2. Most items of XXX are suitable: copy via `INCLUDING XXX`, then apply minor manual adjustments afterward.
3. Only a small subset of XXX items are needed: skip copying entirely with `EXCLUDING XXX`, with optional follow-up tweaks.
Extending this logic to the full set of attributes covered by `ALL`:
1. Every attribute works as expected: use `INCLUDING ALL` with zero follow-up changes.
2. Most attributes are applicable: either copy everything with `INCLUDING ALL` and tweak afterward,
or use `INCLUDING ALL` paired with `EXCLUDING XXX/YYY/ZZZ...` to exclude unwanted categories.
3. Only a minority of attributes are required: opt for `EXCLUDING ALL`, then explicitly list needed items
via `INCLUDING XXX/YYY/ZZZ...`.
The current syntax design covering `INCLUDING`, `EXCLUDING`, and `ALL` already offers adequate
flexibility for users to make top-level copy decisions.
One-to-one copying works reliably when exactly one source table is used.
Multi-table scenarios constitute the only exceptional case where the command’s behavior diverges
from single-table usage. If we can resolve the merging logic properly, I believe merging comments
would be a reasonable approach. I do not think introducing brand-new dedicated syntax options is
necessary for this scenario. At this stage, I have not come up with a more elegant alternative solution.
regards,
--
ZizhuanLiu (X-MAN)
44973863(at)qq(dot)com
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Fujii Masao | 2026-07-24 02:06:42 | Collect ALTER PUBLICATION commands for event triggers |
| Previous Message | Ian Lawrence Barwick | 2026-07-24 01:35:10 | Re: Remove getpgusername() |