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 1svyKW-0014Zh-ON for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Oct 2024 12:19:45 +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 1svyKV-00F5aT-Ah for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Oct 2024 12:19:43 +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 1svyKU-00F5aH-Cz for pgsql-hackers@lists.postgresql.org; Wed, 02 Oct 2024 12:19:42 +0000 Received: from fout-a2-smtp.messagingengine.com ([103.168.172.145]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1svyKR-00287A-Bd for pgsql-hackers@lists.postgresql.org; Wed, 02 Oct 2024 12:19:41 +0000 Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfout.phl.internal (Postfix) with ESMTP id 590AD13802BF; Wed, 2 Oct 2024 08:19:38 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Wed, 02 Oct 2024 08:19:38 -0400 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-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1727871578; x= 1727957978; bh=Z+T1peZIxLNhM5TGEDjmmCvNC6Sj6nCiojPqtlY2HNQ=; b=N 7plNNaBWsZBU4g9qtY9/C38BySRrclzSS3M7HJqaRR3dduqQSYc/EdaxZS7euyr+ TKARY3soQPrdPVzf3tNBKbJuajEk7wRQUSLyI117Z1o31+5bi6FEcOSBonQ8vHbY LetGlIZuUy5EQmMEGmIzaFH4PeCwONZxYZOvFOhaDbZjRZg94YfHvTxl+Z8w7RCI mV4skR4rxb8sywXL6zN6gOTRt6FzrGjhgjzt3WLSvK6Nclix83de76kn1mG3MQRW ioOUQVMxNFbjyaxuRKt5zrzCg1OjeXxLsSQNcCWV+tLOfcnr9WeXq1lJvhsatojN MM0mnkcL8zFW30RadFMjA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdduledggeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkgggtugfgjgesthekredttddtjeen ucfhrhhomheptehlvhgrrhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhh drnhhoqdhiphdrohhrgheqnecuggftrfgrthhtvghrnhepvdektdffudfftdffffehfffh jeejhffgieeuueekjeekfffgudffhfduffffueevnecuffhomhgrihhnpegvnhhtvghrph hrihhsvggusgdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgr ihhlfhhrohhmpegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgpdhnsggprh gtphhtthhopeefpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehjihgrnhdruhhn ihhvvghrshgrlhhithihsehgmhgrihhlrdgtohhmpdhrtghpthhtohepthhnughrfigrnh hgsehgmhgrihhlrdgtohhmpdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrsheslhhi shhtshdrphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 2 Oct 2024 08:19:37 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1727871575; bh=Uc6A6GJIey/7lPl2EnzsVG4cKdP4P48HaWz9nDPCndc=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=WaQvfXvqKCygz+to9eF3wPjuSo591Qh6ULIhiVcG70f9YlUAbkbeJ1dm998n6eE0L NgXJLLtLKfuC+dICHqXCuVeSHoKi3Y9g1EYvZ0lFvCez2KQjE9it23WdqFR9vwiLxJ NSarDhGKCqVJj96XDMWVXnOtrfO0Paro5Ua6DwWWPmFRJqQkPrJnnQG1vqPtb9RiET XF+K0oxkCyk783Zzl792TOHZgNc2upPRvqBAEh5fW7UneS9mD4dqpFJUa7EKk0CeYc GWeJwAkjhSye6L1I7SOWVU49DHgMARcyz/ExcM1Stz+0C9Y4NfKUQ78boYsx8NUWQL 2mCNJOmlo8vgg== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 1F381A2; Wed, 2 Oct 2024 14:19:35 +0200 (CEST) Date: Wed, 2 Oct 2024 14:19:35 +0200 From: Alvaro Herrera To: jian he Cc: Tender Wang , Pg Hackers Subject: Re: not null constraints, again Message-ID: <202410021219.bvjmxzdspif2@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-Oct-02, jian he wrote: > On Tue, Oct 1, 2024 at 11:20 PM Alvaro Herrera wrote: > > > > On 2024-Oct-01, jian he wrote: > > > > > create table t2 (a int primary key constraint foo not null no inherit); > > > primary key cannot coexist with not-null no inherit? > > > here t2, pg_dump/restore will fail. > > > > Yeah, this needs to throw an error. If you use a table constraint, it > > does fail as expected: > > > > create table notnull_tbl_fail (a int primary key, not null a no inherit); > > ERROR: conflicting NO INHERIT declaration for not-null constraint on column "a" > > > > I missed adding the check in the column constraint case. > > > after v7, still not bullet-proof. as before, pg_dump/restore will fail > for the following: > > drop table if exists t2, t2_0 > create table t2 (a int, b int, c int, constraint foo primary key(a), > constraint foo1 not null a no inherit); > create table t2_0 (a int constraint foo1 not null no inherit, b int, c > int, constraint foo12 primary key(a)); Rats. Fixing :-) > drop table if exists idxpart,idxpart0,idxpart1 cascade; > create table idxpart (a int not null) partition by list (a); > create table idxpart0 (a int constraint foo not null no inherit); > alter table idxpart attach partition idxpart0 for values in (0,1); > > With V7, we basically cannot change the status of "NO INHERIT". > now, we need to drop the not-null constraint foo, > recreate a not-null constraint on idxpart0, > then attach it to the partitioned table idxpart. Yeah, that sucks. We'll need a new command ALTER TABLE .. ALTER CONSTRAINT .. INHERIT (exact syntax TBD) which allows you to turn a NO INHERIT constraint into a normal one, to avoid this problem. I suggest we don't hold up this patch for that. > --------------------------------------------------------------------------------- > drop table if exists inh_parent,inh_child1,inh_child2; > create table inh_parent(f1 int); > create table inh_child1(f1 int not null); > alter table inh_child1 inherit inh_parent; > alter table only inh_parent add constraint nn not null f1; > alter table only inh_parent alter column f1 set not null; > > minor inconsistency, i guess. > "alter table only inh_parent add constraint nn not null f1;" > will fail. > But > "alter table only inh_parent alter column f1 set not null;" > will not fail, but add a "NOT NULL f1 NO INHERIT" constraint. > I thought they should behave the same. > > > for partitioned table > now both ALTER TABLE ONLY ADD CONSTRAINT NOT NULL, > ALTER TABLE ONLY ALTER COLUMN SET NOT NULL > will error out. > I am fine with partitioned table behavior. Yeah, this naughty relationship between ONLY and NO INHERIT is bothersome and maybe we need to re-examine it. -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ #error "Operator lives in the wrong universe" ("Use of cookies in real-time system development", M. Gleixner, M. Mc Guire)