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: Álvaro Herrera <alvherre(at)kurilemu(dot)de>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: pg_dump misses comments on NOT NULL constraints
Date: 2025-06-25 15:39:38
Message-ID: CACJufxGt_enGxs==KM=mnBzTOJ8Ytc06nw6zp53ihHKiZ_pGuw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Jun 25, 2025 at 11:04 PM Fujii Masao
<masao(dot)fujii(at)oss(dot)nttdata(dot)com> wrote:
> >>
> >> This commit corrects the behavior by ensuring CREATE TABLE LIKE to also copy
> >> the comments on NOT NULL constraints when INCLUDING COMMENTS is specified.
> >
> > LGTM. I'd add a line in the test showing that these comments are copied
> > even if INCLUDING CONSTRAINTS is not given,
>
> +1 to adding that test.
>
> CREATE TABLE ctlt1_inh (LIKE ctlt1 INCLUDING CONSTRAINTS INCLUDING COMMENTS) INHERITS (ctlt1);
> \d+ ctlt1_inh
> -SELECT description FROM pg_description, pg_constraint c WHERE classoid = 'pg_constraint'::regclass AND objoid = c.oid AND c.conrelid = 'ctlt1_inh'::regclass;
> +SELECT conname, description FROM pg_description, pg_constraint c WHERE classoid = 'pg_constraint'::regclass AND objoid = c.oid AND c.conrelid = 'ctlt1_inh'::regclass ORDER BY conname COLLATE "C";
>
> However, since ctlt1_inh is created with INCLUDING COMMENTS, this test
> doesn't seem to demonstrate the case you mentioned — that comments on
> not-null constraints are copied even without INCLUDING CONSTRAINTS.
> Am I misunderstanding?

to do that,
we can create another table in create_table_like.sql:
CREATE TABLE noinh_con_copy2 (LIKE noinh_con_copy INCLUDING COMMENTS);

or change noinh_con_copy1 definition to
CREATE TABLE noinh_con_copy1 (LIKE noinh_con_copy INCLUDING COMMENTS);

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Álvaro Herrera 2025-06-25 15:45:06 Re: pg_dump misses comments on NOT NULL constraints
Previous Message Fujii Masao 2025-06-25 15:39:08 Re: pg_dump misses comments on NOT NULL constraints