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 1tBZ7q-004eVj-Vj for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Nov 2024 12:39:06 +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 1tBZ7n-003Mqg-Sc for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Nov 2024 12:39:04 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tBZ7n-003MqY-9I for pgsql-hackers@lists.postgresql.org; Thu, 14 Nov 2024 12:39:04 +0000 Received: from fhigh-b4-smtp.messagingengine.com ([202.12.124.155]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tBZ7j-001tJN-Pj for pgsql-hackers@postgresql.org; Thu, 14 Nov 2024 12:39:03 +0000 Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.stl.internal (Postfix) with ESMTP id 528A225401F6; Thu, 14 Nov 2024 07:38:58 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Thu, 14 Nov 2024 07:38:58 -0500 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=fm3; t=1731587938; x=1731674338; bh=u qi8tImQoYqrV2yJRQm0wGSE37CkRL+laMfBtBPeP5I=; b=Ts/bwu0txzH8gX+VZ g9aduN/M1OLjjJwEXxPb9zKfNmCZ7Lnwh6SJZhbCnvVEJSiq9JLM0c7CxhZVBSQf Is/04/H8sBXv9Zyowna+Jn3nBrfGOY93uKIU8NZInYT77IVy/dZyb02D5MjL7cYZ gGvyFX0t3IQgOlMlXicd4PewCFFMN1DR+uhLnIUrRopn1P3sD5nbcH3Qf11HVYSy gmd7rA3smjp2Wg0aXQaJqGmBw2cvtKmZVESpZki9pA22ZjnGE5/KCXtpoxbyJWHv qc7wjihCttwiSFChq/kde+k1s6TB9e6sZlceZzXi6PJ0lD+Pqk6Z0wzTJfcvIHB8 Q+bgw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrvddvgdegvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepfffhvfevuf fkgggtugfgjgesthekredttddtjeenucfhrhhomheptehlvhgrrhhoucfjvghrrhgvrhgr uceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgheqnecuggftrfgrthhtvg hrnhepvdektdffudfftdffffehfffhjeejhffgieeuueekjeekfffgudffhfduffffueev necuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomhenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhvhhgvrhhrvgesrghlvhhh rdhnohdqihhprdhorhhgpdhnsggprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuth dprhgtphhtthhopegrshhhuhhtohhshhdrsggrphgrthdrohhsshesghhmrghilhdrtgho mhdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehpohhsthhgrhgvshhqlhdroh hrgh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 14 Nov 2024 07:38:57 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1731587936; bh=KDilJoaIikV/ODabM8JoV6KQme1kwhMrQeGITVPzqhw=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=Xm651Qng51VdpwjBqmFNsZS9u+T+geoWq2MzXt4SOfD0KHHqj5AcSbHrVzm2Rdqfj cJb/ALbVSL2xbKlUmdo1YHZ5ViteaAdwU6Trfutwi0m/opIvjkhmeev2cEf0Zh2nR1 9gH1EvQaOZ2fjn7MwycxoFuihV77vaXm/k2OIf6N7Mjm+6hIlW4tF7UuICn7z+gmTm bfoBourGlbzg+I0gEhFMVAD3O8V5NLztWZha5Qca//Whc1gFX/jmMr1mudAoX4qY/C RzWHXmyDjCQgpffuDzdD56SViB2oOEyKAaJQ85Zz17Qa+lKCWdY61rJYy5F4CBYlRj jj3WWkJe3x0Mg== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 16CD2EE; Thu, 14 Nov 2024 13:38:56 +0100 (CET) Date: Thu, 14 Nov 2024 13:38:56 +0100 From: Alvaro Herrera To: Ashutosh Bapat Cc: pgsql-hackers Subject: Re: Difference in dump from original and restored database due to NOT NULL constraints on children Message-ID: <202411141238.d4x2cfufzlw3@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 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 Hello Ashutosh, On 2024-Nov-14, Ashutosh Bapat wrote: > Because of the test I am developing under discussion at [1], I noticed > that the DDLs dumped for inheritance children with NOT NULL > constraints defer between original database and database restored from > a dump of original database. I investigated those differences, but can > not decide whether they are expected and whether they are intentional > or not. Look something related to > 14e87ffa5c543b5f30ead7413084c25f7735039f. It does and it is, thanks. So there are two differences: 1. CREATE TABLE generated_stored_tests.gtest1 ( a integer NOT NULL, b integer GENERATED ALWAYS AS ((a * 2)) STORED ); CREATE TABLE generated_stored_tests.gtestxx_4 ( - a integer, - b integer NOT NULL + a integer NOT NULL, + b integer ) INHERITS (generated_stored_tests.gtest1); In this case, I think it's wrong to add NOT NULL to gtestxx_4.a because the constraint was not local originally and it should be acquired by the inheritance. I'm not sure about gtestxx_4.b ... the GENERATED constraint should induce a not-null if I recall correctly, so an explicit not-null marking in the child might not be necessary. But I'll have a look. 2. CREATE TABLE public.notnull_tbl4 ( a integer NOT NULL ); CREATE TABLE public.notnull_tbl4_cld2 ( ) INHERITS (public.notnull_tbl4); -ALTER TABLE ONLY public.notnull_tbl4_cld2 ALTER COLUMN a SET NOT NULL; +ALTER TABLE ONLY public.notnull_tbl4_cld2 ADD CONSTRAINT notnull_tbl4_a_not_null NOT NULL a; CREATE TABLE public.notnull_tbl4_cld3 ( ) INHERITS (public.notnull_tbl4); -ALTER TABLE ONLY public.notnull_tbl4_cld3 ADD CONSTRAINT a_nn NOT NULL a; +ALTER TABLE ONLY public.notnull_tbl4_cld3 ADD CONSTRAINT notnull_tbl4_a_not_null NOT NULL a; For notnull_tbl4_cld2 we try to set the column not-null, but it's already not-null due to inheritance ... so why are we doing that? Weird. These lines should just go away in both dumps. In notnull_tbl4_cld3's case we have the same, but we also want to set a constraint name, but the constraint already exists, so that doesn't work, and that's the reason why the next dump uses the standard name. Maybe we could dump the name change as ALTER TABLE RENAME CONSTRAINT in that case instead, _if_ we can obtain the original name (should be doable, because we can see it's a nonstandard name.) -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/