Re: pg_dump does not dump domain not-null constraint's comments
Álvaro Herrera <alvherre@kurilemu.de>
From: Álvaro Herrera <alvherre@kurilemu.de>
To: jian he <jian.universality@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-07-21T09:48:52Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix pg_dump COMMENT dependency for separate domain constraints.
- a685c057ad4c 13.23 landed
- 85d6ed31fc7c 14.20 landed
- 0773f3a875f1 15.15 landed
- e127764b65da 17.7 landed
- 4ad846445dd0 18.0 landed
- 3cf328eca84a 16.11 landed
- c044b50d199c 19 (unreleased) landed
-
pg_dump: include comments on not-null constraints on domains, too
- f9545e95c5e7 18.0 landed
- da71717f0a7c 19 (unreleased) landed
- 6b755d8d70b2 17.6 landed
-
Fix dumping of comments on invalid constraints on domains
- e04aca1c4d33 14.19 landed
- dca0e9693b71 18.0 landed
- d07bc7c2b3ca 17.6 landed
- cef998ef8314 16.10 landed
- 5a261c135d43 15.14 landed
- 57949cea5af0 13.22 landed
- 0858f0f96ebb 19 (unreleased) landed
-
Catalog domain not-null constraints
- e5da0fe3c22b 17.0 cited
-
In pg_dump, don't dump a stats object unless dumping underlying table.
- 7418767f11d1 17.0 cited
-
Enable CHECK constraints to be declared NOT VALID
- 897795240cfa 9.2.0 cited
On 2025-Jul-18, jian he wrote:
> one minor issue in getDomainConstraints:
>
> for (int i = 0, j = 0; i < ntups; i++)
> {
> char contype = (PQgetvalue(res, i, i_contype))[0];
> ....
> constraint->contype = *(PQgetvalue(res, i, i_contype));
> }
>
> for the same code simplicity,
> ``constraint->contype = *(PQgetvalue(res, i, i_contype));``
> can change to
> `` constraint->contype = contype; ``
> ?
> other than that, looks good to me.
Thanks, changed it that way.
I noticed some other issues however. First, you had removed the contype
comparisons in repairDependencyLoop; I put them back several versions of
the patch ago, but I had mistakenly made them reference the wrong array
item -- in all three places. Doh.
Second, the name comparisons to determine whether to list the constraint
name in the "CREATE DOMAIN .. NOT NULL" syntax was wrong: it was using
fmtId() around the constraint name, but of course that would have never
worked, because we're comparing to the original string, not a quoted
name. So if you had a domain called, say
CREATE DOMAIN "my domain" AS int NOT NULL;
then pg_dump would have said
CREATE DOMAIN "my domain" AS int CONSTRAINT "my domain_not_null" NOT NULL;
even though listing the name is unnecessary. This wouldn't have made
the dump fail, so it's borderline; but it would be /slightly/ ugly.
Lastly, I made dumpDomain print unadorned "NOT NULL" if a pg_constraint
row for the constraint is not found and yet we observe typnotnull set.
This can be considered catalog corruption (the row should be there), but
I think this is better than having pg_dump just crash if that row is not
there.
--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
Voy a acabar con todos los humanos / con los humanos yo acabaré
voy a acabar con todos (bis) / con todos los humanos acabaré ¡acabaré! (Bender)