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 1t95gR-007iQn-CA for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Nov 2024 16:48:34 +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 1t95gO-00HUCh-GY for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Nov 2024 16:48:33 +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 1t95gO-00HUCZ-3P for pgsql-hackers@lists.postgresql.org; Thu, 07 Nov 2024 16:48:32 +0000 Received: from fout-b5-smtp.messagingengine.com ([202.12.124.148]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t95gK-000hjH-Ah for pgsql-hackers@lists.postgresql.org; Thu, 07 Nov 2024 16:48:32 +0000 Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfout.stl.internal (Postfix) with ESMTP id 866DD11400EF; Thu, 7 Nov 2024 11:48:27 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Thu, 07 Nov 2024 11:48:27 -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=1730998107; x=1731084507; bh=C toWjCeHRt5Kr/OivljBhzWwH+nKgTN3gAyQ6r/+jAg=; b=RsH2gXtmXrB3L/sfH 8lG1PdG0cANLW9rY4hA73gVSrAy22rU7wuJsedQirFuwBaG9zvPO753eWmQPVa2N LWIXmkDyOXpCYY1dtw2hDwXMxxN7MFJMP2a2Ucar5WDtQxaOFXw3fvSDnHqkTYdu Lh4ZpRBfWQLOmYOz1wLljwdy9gbFGSqvJA21dprX+m33ZxQdJujoTyJbZyOuSMGZ f59tZuES3OtCsR0P6NaNHfSww4xdKn7vK+spbTxneYPp4XRO7qbABlVp0imQuhZc um3UaHlYwiLpUV28rM6l7+F2ixLAbYeEkvtkwAV5JB/+h8kdjR9Qatjp5S4IBfEC 5hySw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrtdeggdelvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfggtggugfgjsehtkeertddttdejnecu hfhrohhmpeetlhhvrghrohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrd hnohdqihhprdhorhhgqeenucggtffrrghtthgvrhhnpedvkedtffduffdtffffheffhfej jefhgfeiueeukeejkeffgfdufffhudffffeuveenucffohhmrghinhepvghnthgvrhhprh hishgvuggsrdgtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghi lhhfrhhomheprghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrghdpnhgspghrtg hpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepjhhirghnrdhunhhi vhgvrhhsrghlihhthiesghhmrghilhdrtghomhdprhgtphhtthhopehtnhgurhifrghngh esghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehlihhs thhsrdhpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 7 Nov 2024 11:48:26 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1730998104; bh=J5WWnlnat+5TzbXyjZnn0fCdy3zJF4oApJdndJb+E+g=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=psc4Z8hibnjCmBKzZE4geOhfpywxE13CFau9HUCzAP7QrJ7UfIF3LE6YytEDYV2C+ InR0H5rF194/MVtAaeo5fmZKU3c1SZErIKdZWUsl7x+L+PcxQ8MLmJ7PgElsNnBSAi s6sqUijg6powTyJuW739UKQZeUN4EJ1XQ+z6I8+WXKnwygtj9zCzuA2ALtxVVFUSX1 SO7cAaPbhwsAn12ekCm6EPWMrQ/BMWivX8NE43a1VlkAXTCPRQXb5V0BA45RNaBHHN A+BidMPQe1Z5a7ebWUsqJuP4tnUYqKK8c76rxuX7ew3wZl4MuNRJ2LV54+e4/xWB2f As1movGG8JEzQ== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 0A20F9B; Thu, 7 Nov 2024 17:48:24 +0100 (CET) Date: Thu, 7 Nov 2024 17:48:24 +0100 From: Alvaro Herrera To: jian he Cc: Pg Hackers , Tender Wang Subject: Re: not null constraints, again Message-ID: <202411071648.b7eixytkwzbe@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 On 2024-Nov-07, jian he wrote: > RemoveInheritance > if (copy_con->coninhcount <= 0) /* shouldn't happen */ > elog(ERROR, "relation %u has non-inherited constraint \"%s\"", > RelationGetRelid(child_rel), NameStr(copy_con->conname)); > dropconstraint_internal > if (childcon->coninhcount <= 0) /* shouldn't happen */ > elog(ERROR, "relation %u has non-inherited constraint \"%s\"", > childrelid, NameStr(childcon->conname)); > > RemoveInheritance error triggered (see below), dropconstraint_internal may also. > that means the error message should use RelationGetRelationName > rather than plain "relation %u"? > > drop table if exists inh_parent,inh_child1,inh_child2; > create table inh_parent(f1 int not null no inherit); > create table inh_child1(f1 int not null no inherit); > alter table inh_child1 inherit inh_parent; > alter table inh_child1 NO INHERIT inh_parent; > ERROR: relation 26387 has non-inherited constraint "inh_child1_f1_not_null" Hmm, no, this is just a code bug: in RemoveInheritance when scanning 'parent' for constraints, we must skip the ones that are NO INHERIT, but weren't. With the bug fixed, the sequence above results in a no-longer-child inh_child1 that still has inh_child1_f1_not_null, and no error is thrown. > sql-altertable.html > INHERIT parent_table > This form adds the target table as a new child of the specified parent table. > Subsequently, queries against the parent will include records of the target > table. To be added as a child, the target table must already contain all the > same columns as the parent (it could have additional columns, too). The columns > must have matching data types, and if they have NOT NULL constraints in the > parent then they must also have NOT NULL constraints in the child. > > " > The columns must have matching data types, and if they have NOT NULL > constraints in the > parent then they must also have NOT NULL constraints in the child. > " > For the above sentence, we need to add some text to explain > NOT NULL constraints, NO INHERIT property > for the child table and parent table. True. I rewrote as follows, moving the whole explanation of constraints together to the same paragraph, rather than talking about some constraints in one paragraph and other constraints in another. The previous approach was better when NOT NULL markings were a property of the column, but now that they are constraints in their own right, this seems better. INHERIT parent_table This form adds the target table as a new child of the specified parent table. Subsequently, queries against the parent will include records of the target table. To be added as a child, the target table must already contain all the same columns as the parent (it could have additional columns, too). The columns must have matching data types. In addition, all CHECK and NOT NULL constraints on the parent must also exist on the child, except those marked non-inheritable (that is, created with ALTER TABLE ... ADD CONSTRAINT ... NO INHERIT), which are ignored. All child-table constraints matched must not be marked non-inheritable. Currently UNIQUE, PRIMARY KEY, and FOREIGN KEY constraints are not considered, but this might change in the future. > ------------------------------------------------ > drop table if exists inh_parent,inh_child1,inh_child2; > create table inh_parent(f1 int not null no inherit); > create table inh_child1(f1 int); > alter table inh_child1 inherit inh_parent; > alter table inh_child1 NO INHERIT inh_parent; > ERROR: 1 unmatched constraints while removing inheritance from "inh_child1" to "inh_parent" > > now, we cannot "uninherit" inh_child1 from inh_parent? > not sure this is expected behavior. Yeah, this is the same bug as above. -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ "In fact, the basic problem with Perl 5's subroutines is that they're not crufty enough, so the cruft leaks out into user-defined code instead, by the Conservation of Cruft Principle." (Larry Wall, Apocalypse 6)