Re: pg_dump misses comments on NOT NULL constraints

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org, Álvaro Herrera <alvherre(at)kurilemu(dot)de>
Subject: Re: pg_dump misses comments on NOT NULL constraints
Date: 2025-06-19 05:42:09
Message-ID: CACJufxGM0shyqsiGeehJpEBonTvxU6FW5go1BBg50bcfJ67tPg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Jun 18, 2025 at 10:21 AM Fujii Masao
<masao(dot)fujii(at)oss(dot)nttdata(dot)com> wrote:
>
> I ran into another issue related to comments on NOT NULL constraints.
> When using CREATE TABLE ... (LIKE ... INCLUDING ALL), the NOT NULL constraints
> are copied, but their comments are not. For example:
>
> -----------------------------------------------------
> =# CREATE TABLE t (i int);
> =# ALTER TABLE t ADD CONSTRAINT my_not_null_i NOT NULL i;
> =# ALTER TABLE t ADD CONSTRAINT my_check_i CHECK (i > 0);
> =# COMMENT ON CONSTRAINT my_not_null_i ON t IS 'my not null for i';
> =# COMMENT ON CONSTRAINT my_check_i ON t IS 'my check for i';
>
> =# CREATE TABLE t_copied (LIKE t INCLUDING ALL);
>
> As shown, the comment on my_not_null_i is not copied to the new table,
> even though the constraint itself is. Could this be another oversight
> in commit 14e87ffa5c5?
>

hi.
in transformTableLikeClausem, let cxt(CreateStmtContext) to add
CommentStmt should just work.
Please check attached, tests also added.

Attachment Content-Type Size
v1-0001-fix-create-table-like-not-copy-not-null-constraint-s-comm.patch application/x-patch 5.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nisha Moond 2025-06-19 05:56:11 Re: Logical Replication of sequences
Previous Message Amit Kapila 2025-06-19 05:13:10 Re: Adding a '--clean-publisher-objects' option to 'pg_createsubscriber' utility.