Re: pg_dump does not dump domain not-null constraint's comments

From: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
To: jian he <jian(dot)universality(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: pg_dump does not dump domain not-null constraint's comments
Date: 2025-07-21 09:48:52
Message-ID: 202507210948.lljgqgrrnm5v@alvherre.pgsql
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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)

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Dilip Kumar 2025-07-21 09:54:39 Re: Logical Replication of sequences
Previous Message Dilip Kumar 2025-07-21 09:42:50 Re: Logical Replication of sequences