Re: pg_dump misses comments on NOT NULL constraints

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

On 2025-Jun-18, jian he wrote:

> Similarly we don't need to worry about not-null constraints that are
> dumped separately.
> dumpConstraint, dumpTableConstraintComment will do the job.

Right.

> dumpTableSchema handles dumping of table column definitions, and tells us which
> column print_notnull is true. Since we already know which columns have had
> their not-null constraints printed, it makes sense to dump inline not-null
> comments here too.

I agree that this is roughly the right approach, but I think you're
doing it harder than it needs to be -- it might be easier to add a JOIN
to pg_description to the big query in getTableAttrs(), and add a pointer
to the returned string in tbinfo->notnull_comments[j] (for versions
earlier than 18, don't add the join and have it return constant NULL).
Then in dumpTableSchema, in the place where you added the new query,
just scan that array and print COMMENT ON commands for each valid
constraint where that's not a null pointer.

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"Aprender sin pensar es inútil; pensar sin aprender, peligroso" (Confucio)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message shihao zhong 2025-06-18 15:15:31 Fixes inconsistent behavior in vacuum when it processes multiple relations
Previous Message jian he 2025-06-18 14:35:54 Re: pg_dump misses comments on NOT NULL constraints