Re: pg_dump misses comments on NOT NULL constraints - Mailing list pgsql-hackers

From Álvaro Herrera
Subject Re: pg_dump misses comments on NOT NULL constraints
Date
Msg-id 202506181505.6wtpte7cowdy@alvherre.pgsql
Whole thread Raw
In response to pg_dump misses comments on NOT NULL constraints  (Fujii Masao <masao.fujii@oss.nttdata.com>)
Responses Re: pg_dump misses comments on NOT NULL constraints
List 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)



pgsql-hackers by date:

Previous
From: Mihail Nikalayeu
Date:
Subject: Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements
Next
From: Jeff Davis
Date:
Subject: Re: pg_dump --with-* options