Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ubftr-003pC3-8e for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Jul 2025 13:40:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1ubfto-002AK2-6A for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Jul 2025 13:40:48 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ubftm-002AJs-Uj for pgsql-hackers@lists.postgresql.org; Tue, 15 Jul 2025 13:40:48 +0000 Received: from fout-a1-smtp.messagingengine.com ([103.168.172.144]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1ubftl-007PZd-06 for pgsql-hackers@lists.postgresql.org; Tue, 15 Jul 2025 13:40:46 +0000 Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id D8652EC1251; Tue, 15 Jul 2025 09:40:43 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Tue, 15 Jul 2025 09:40:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kurilemu.de; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to; s=fm1; t=1752586843; x= 1752673243; bh=PeLCFqwCGz2b5Tk+XYrMwzR6GQZ9t7JAYdcLt/P8QII=; b=m 3dAISBNfNwWEpQDhLhbrOauLMbausyFVguT6BvmLUkzBK9aOo7+n2V0VCv0mEnOr TWc9lmyAbeU1TvF0xrAWg70r3dneN7pG3eftc0GMdChVcf8lZh0e6yjb3ogoJ/HQ b+J99IfLxjvfbFMyehmGXQ4aHvD4/LRFeiKZqU7/XpOkrPSb2wT6CCokPor1IhS5 QomIhTlPU94uDUa+4IsS7w/91mtPq0TAjxAoYHIIxGHNwrFejdkIm30x/C/J5Mgl RE1klvpJHgSz2ZumNNJSo79JJDcojD6SbE2ETY49pilBNLiJ11aGhTyeTdZ5nKS5 YusxOPE9O64iERRlmUw6A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1752586843; x=1752673243; bh=P eLCFqwCGz2b5Tk+XYrMwzR6GQZ9t7JAYdcLt/P8QII=; b=lV3YZV65S9IUphL8F 5Z0eOt2zu/WlGvRrx2HINwCbLAP8nf5ezuyUU/1ChZNrNUx0jQdJQi5VgIo4IjQA bqvS/1cyavAe9PPcpALHNDnV+rsF2bP2+xHKTx0m9un2G5cmKjUVdkUP3EP1s/YQ Y6JZfmy8APHZJ6IssAJGdMs7OhZ0HIVlCa8DBpQeG9Q/1S7IgMwGDRiXTx3DoDLa Cv6U1hufjU7r2Vrfj/pByAM35hupufUSSonEuApuhWNhmdC2RQv+N+Pet8M4cRIO G2Owvegl0o3YzhiLp78aoumRme/Uo/esyxS5DYFYP4Q7fIInYzI0qt5uRs2gxjG7 yPxEw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdehgeeljecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpeffhffvvefukfggtggugfgjsehmkeerredttdejnecuhfhrohhmpemllhhvrghrohcu jfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgeskhhurhhilhgvmhhurdguvgeqnecuggftrf grthhtvghrnhepgedutedujeehudevveegheejgeelveevvedvuedtjedtkeeuhfehheeg vedtjeetnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomhenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhvhhgvrhhrvges khhurhhilhgvmhhurdguvgdpnhgspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouh htpdhrtghpthhtohepjhhirghnrdhunhhivhgvrhhsrghlihhthiesghhmrghilhdrtgho mhdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehlihhsthhsrdhpohhsthhgrh gvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: ie3de48e3:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 15 Jul 2025 09:40:42 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kurilemu.de; s=schmee; t=1752586838; bh=efxpwTTJxckUwMoKmqKYCqQCHkZTCRIcT2wL8aKweCk=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=fuC0oSKdz+KcYy0I9hb3SlYwwhpsYpaFrzylpLLTaOBrxV/KYZY3PS6TwEpd832vB OItXaqa44vSLGezj/GR/ysrypZxDGc8zvUtjGGzyctXXvS1KclBXIjmBXHcSRytJ0D YUttiIBGQS9JduNEkqbDdfmz5biVKsO0rkG1plYFmmfPy1jqmrpkX9vBqK4EgDqB+T j1wQzlhHR6rQ/nTs5HCiWc2Hj7fXgsw3uxXi0nYzKXAz+62x6ZJHZF9PDQG897Kk0O gjPCTbIaaxdWF6OZR6F7FxZ5Yw6EILSJU68J6vJXYHdwNVq+k2ZBhl2Io5wMmJ+h94 mevQ92mQcZTMQ== Received: by schmee.kurilemu.internal (Postfix, from userid 1000) id CEDB58D; Tue, 15 Jul 2025 15:40:38 +0200 (CEST) Date: Tue, 15 Jul 2025 15:40:38 +0200 From: =?utf-8?Q?=C3=81lvaro?= Herrera To: jian he Cc: PostgreSQL Hackers Subject: Re: pg_dump does not dump domain not-null constraint's comments Message-ID: <202507151340.d4jyrbdae5af@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="2pg2gr6gj4qxbkrc" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --2pg2gr6gj4qxbkrc Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2025-Jul-15, jian he wrote: > On Tue, Jul 15, 2025 at 2:10 PM jian he wrote: > > accidently found another existing bug. > > CREATE SCHEMA test; > > CREATE DOMAIN test.d1 AS integer NOT NULL DEFAULT 11; > > COMMENT ON CONSTRAINT a2 ON DOMAIN test.d1 IS 'test'; > > ALTER DOMAIN test.d1 > > ADD CONSTRAINT a2 CHECK ((VALUE > 1)) NOT VALID; > > > > Obviously the COMMENT command will error out. > > currently working on a fix, just sharing the bug details in advance. Ouch, ugh. I think this is as old as NOT VALID constraints on domains, maybe from commit 897795240cfa (Jun 2011), or ... no, actually 7eca575d1c28 (Dec 2014) which enabled constraints on domains to have comments. In either case it's my fault, and the fix needs to be backpatched all the way back, so I'm going to apply this bugfix one ahead of the others, which are for newer bugs. > we should let: > dumpConstraint handles dumping separate "NOT VALID" domain constraints along > with their comments. > dumpDomain: handles dumping "inlined" valid (not separate) domain constraints > together with their comments. Yeah, this makes sense. > tested locally, i didn't write the test on src/bin/pg_dump/t/002_pg_dump.pl.... I'll add something for coverage, but not yet sure if it's going to be something in 002_pg_dump.pl, or objects to be left around for the pg_upgrade test to pick up. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ --2pg2gr6gj4qxbkrc Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename="0001-Fix-dumping-of-comments-on-invalid-constraints-on-do.patch" From fa407dccc9782d8f3accdcf4045ab9bb8859aef9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Herrera?= Date: Tue, 15 Jul 2025 15:24:33 +0200 Subject: [PATCH] Fix dumping of comments on invalid constraints on domains We skip dumping constraints together with domains if they are invalid ('separate') so that they appear after data -- but their comments were dumped together with the domain definition, which in effect leads to the comment being dumped when the constraint does not yet exist. Delay them in the same way. Oversight in 7eca575d1c28; backpatch all the way back. Author: jian he Discussion: https://postgr.es/m/CACJufxF_C2pe6J_+nPr6C5jf5rQnbYP8XOKr4HM8yHZtp2aQqQ@mail.gmail.com --- src/bin/pg_dump/pg_dump.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 1937997ea67..5af2ac151c2 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -12582,9 +12582,15 @@ dumpDomain(Archive *fout, const TypeInfo *tyinfo) /* Dump any per-constraint comments */ for (i = 0; i < tyinfo->nDomChecks; i++) { ConstraintInfo *domcheck = &(tyinfo->domChecks[i]); - PQExpBuffer conprefix = createPQExpBuffer(); + PQExpBuffer conprefix; + + /* but only if the constraint itself was dumped here */ + if (domcheck->separate) + continue; + + conprefix = createPQExpBuffer(); appendPQExpBuffer(conprefix, "CONSTRAINT %s ON DOMAIN", fmtId(domcheck->dobj.name)); @@ -18487,8 +18493,25 @@ dumpConstraint(Archive *fout, const ConstraintInfo *coninfo) .description = "CHECK CONSTRAINT", .section = SECTION_POST_DATA, .createStmt = q->data, .dropStmt = delq->data)); + + if (coninfo->dobj.dump & DUMP_COMPONENT_COMMENT) + { + char *qtypname; + + PQExpBuffer conprefix = createPQExpBuffer(); + qtypname = pg_strdup(fmtId(tyinfo->dobj.name)); + + appendPQExpBuffer(conprefix, "CONSTRAINT %s ON DOMAIN", + fmtId(coninfo->dobj.name)); + + dumpComment(fout, conprefix->data, qtypname, + tyinfo->dobj.namespace->dobj.name, + tyinfo->rolname, + coninfo->dobj.catId, 0, tyinfo->dobj.dumpId); + destroyPQExpBuffer(conprefix); + } } } else { -- 2.39.5 --2pg2gr6gj4qxbkrc--