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 1qNtE0-006GBP-IM for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Jul 2023 10:55:36 +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 1qNtDz-009e4a-0h for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Jul 2023 10:55:35 +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 1qNtDy-009e4S-Nt for pgsql-hackers@lists.postgresql.org; Mon, 24 Jul 2023 10:55:34 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qNtDu-001VtC-Pl for pgsql-hackers@lists.postgresql.org; Mon, 24 Jul 2023 10:55:34 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id EBDED320091F; Mon, 24 Jul 2023 06:55:28 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 24 Jul 2023 06:55:29 -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:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1690196128; x= 1690282528; bh=3N0MGg+0pOaRlTuQFSBPTvfQDgW+rLtvELKin3LRpAc=; b=v NW6Jw6tfQtNvQGwTuVhmhQwEy3VNAhsEV5Zp3r39DYjoUmi8bMgjKQVl+zjGDJ8O jpqIte6sthP8aPP155SXhcFffX3IBP6lq4ljxyEHfa826TIiEQwDWFNS6GiiEJS6 bSsjYd8xv58nvvl9uFwPu1iSCI95RajFSc/Paty5vAY4/BiL1isQx08tcT0e+6aC DIjfqKFa2pYMNvwB3bUPWOcJszjN6C7VlOiRgKEaZtQ7lG4UtDUHCzcXFkrtsir3 qaVtIFDHH8RenxErE9ynSSctRkY/x+/eNpO22AYX1xFaPBH4b/PMnAPpD2G55w/+ bxWW4o5IC0T3VFLEXwI9A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrheekgdefvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfggtggugfgjsehtkeertddttdejnecuhfhrohhmpeetlhhvrghr ohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgqe enucggtffrrghtthgvrhhnpedvkedtffduffdtffffheffhfejjefhgfeiueeukeejkeff gfdufffhudffffeuveenucffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtohhmne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlvhhh vghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 24 Jul 2023 06:55:28 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 4F1B5A0; Mon, 24 Jul 2023 12:55:26 +0200 (CEST) Date: Mon, 24 Jul 2023 12:55:26 +0200 From: Alvaro Herrera To: Dean Rasheed Cc: Peter Eisentraut , pgsql-hackers@lists.postgresql.org Subject: Re: cataloguing NOT NULL constraints Message-ID: <20230724105526.i3y4avyosaff65ea@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 2023-Jul-24, Dean Rasheed wrote: > Hmm, I'm not so sure. I think perhaps multiple NOT NULL constraints on > the same column should just be allowed, otherwise things might get > confusing. For example: > create table p1 (a int not null check (a > 0)); create table p2 (a int not null check (a > 0)); create table foo () inherits (p1, p2); Have a look at the conislocal / coninhcount values. These should reflect the fact that the constraint has multiple sources; and the constraint does disappear if you drop it from both sources. > If I then drop the p1 constraints: > > alter table p1 drop constraint p1_a_check; > alter table p1 drop constraint p1_a_not_null; > > I end up with column "a" still being not null, and the "p1_a_not_null" > constraint still being there on foo, which seems even more > counter-intuitive, because I just dropped that constraint, and it > really should now be the "p2_a_not_null" constraint that makes "a" not > null: I can see that it might make sense to not inherit the constraint name in some cases. Perhaps: 1. never inherit a name. Each table has its own constraint name always 2. only inherit if there's a single parent 3. always inherit the name from the first parent (current implementation) > So I'd say that ALTER TABLE ... ADD NOT NULL should always add a > constraint, even if there already is one. For example ALTER TABLE ... > ADD UNIQUE does nothing to prevent multiple unique constraints on the > same column(s). It seems pretty dumb, but maybe there is a reason to > allow it, and it doesn't feel like we should be second-guessing what > the user wants. That was my initial implementation but I changed it to allowing a single constraint because of the way the standard describes SET NOT NULL; specifically, 11.15 says that "If the column descriptor of C does not contain an indication that C is defined as NOT NULL, then:" a constraint is added; otherwise (i.e., such an indication does exist), nothing happens. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "La virtud es el justo medio entre dos defectos" (Aristóteles)