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 1t8fF6-005Kpw-Dc for pgsql-hackers@arkaria.postgresql.org; Wed, 06 Nov 2024 12:34: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 1t8fF3-005n3J-1f for pgsql-hackers@arkaria.postgresql.org; Wed, 06 Nov 2024 12:34:33 +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 1t8fF2-005n39-Hf for pgsql-hackers@lists.postgresql.org; Wed, 06 Nov 2024 12:34:33 +0000 Received: from fhigh-a3-smtp.messagingengine.com ([103.168.172.154]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t8fEw-000T9z-2B for pgsql-hackers@lists.postgresql.org; Wed, 06 Nov 2024 12:34:31 +0000 Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfhigh.phl.internal (Postfix) with ESMTP id 7AB1311402AB; Wed, 6 Nov 2024 07:34:24 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Wed, 06 Nov 2024 07:34:24 -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=1730896464; x=1730982864; bh=W sF7Cb0/DVo1Z+w3AZ2wAk0X+nYPK5icxDcNLVXCHaA=; b=fs00WUXvESEXoVIZs z2RcIH+kWgO/rpJu1wRRIJ6hP36Ge5F3nzBgTY4dEpWlHfXiRuksSLnR4tExvrIW imf4gr/19Zc42IJ3QGf4DTEFyb/jH0V/vNsAeINi0x/DGit+EhE0T12sVxPcVw3U qax63OrpIA9TTLFbFM+dM+2O3VqGGEYkRwiOcm1uZqytiRHnLrQra5zS1lARmmGZ vsNMlBJ6dc6wvjgjVvKSOrl1ZXukxRgPkoVulOy3MYNtErIEBZFQ0T1iqIHNQBpO OefnN9sxWVbg4wNpC/l4KnFlvV0eQEw9qTLSF83SeAXMMeX9jnDdotZek/gA4D3g zqZZA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrtddvgdegtdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfggtggugfgjsehtkeertddttdejnecu hfhrohhmpeetlhhvrghrohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrd hnohdqihhprdhorhhgqeenucggtffrrghtthgvrhhnpedvudeftdfgvedvgfffgefhvedu vdeghfdugedufffhgeduudettedthfdvgeffheenucffohhmrghinhepvghnthgvrhhprh hishgvuggsrdgtohhmpdhtfihithhtvghrrdgtohhmnecuvehluhhsthgvrhfuihiivgep tdenucfrrghrrghmpehmrghilhhfrhhomheprghlvhhhvghrrhgvsegrlhhvhhdrnhhoqd hiphdrohhrghdpnhgspghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghp thhtoheprghmihhtlhgrnhhgohhtvgdtleesghhmrghilhdrtghomhdprhgtphhtthhope hrohgsvghrthhmhhgrrghssehgmhgrihhlrdgtohhmpdhrtghpthhtohepphhgshhqlhdq hhgrtghkvghrsheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 6 Nov 2024 07:34:23 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1730896460; bh=NLKmdwsWIsS2M9yFhuUer7Yw9KkwNQ8fl46ih4QZ0aw=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=PBOYIdRHMxQ3I70yqHsjtNONnlUtD3wPuY31js8CUeZ4/8gh2rET9R+jOsdDo/qrW qk+neBeu/i/E/1wpzqWKrJ5m+shdjKTYYzSW8D/B7D0YMAjmDboNzbeequPmqeppLC poUwAqhvz/WQvpGShUN/y52H9DX4saFYz6UdvA4XtKZHemydC/tNl+iT1MZEYd+hyk EfpfWTgHDkHuAkkUOmfz1URG1uLvXnTFAvPSHu8bgll9P2U3VTUaX7S5BG39TV8JR7 28LDWixIS6XiuKEHmJpNS2LluwRc44uRVM5iYQPndGM3otlKOTz9VFecwqTaqv6eRh vGN3y5NRzXwcg== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 0125F9B; Wed, 6 Nov 2024 13:34:19 +0100 (CET) Date: Wed, 6 Nov 2024 13:34:19 +0100 From: Alvaro Herrera To: Amit Langote Cc: Pg Hackers , Robert Haas Subject: Re: doc fail about ALTER TABLE ATTACH re. NO INHERIT Message-ID: <202411061234.3jticfqxgwgd@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-06, Amit Langote wrote: > On Tue, Nov 5, 2024 at 9:01 PM Alvaro Herrera wrote: > > While doing final review for not-null constraints, I noticed that the > > ALTER TABLE ATTACH PARTITION have this phrase: > > > > If any of the CHECK constraints of the table being attached are marked NO > > INHERIT, the command will fail; such constraints must be recreated without the > > NO INHERIT clause. > I think that text might be talking about this case: > > create table parent (a int, constraint check_a check (a > 0)) > partition by list (a); > create table part1 (a int, constraint check_a check (a > 0) no inherit); > alter table parent attach partition part1 for values in (1); > ERROR: constraint "check_a" conflicts with non-inherited constraint on child table "part1" Oh, hmm, that makes sense I guess. Still, while this restriction makes sense for inheritance, it doesn't IMO for partitioned tables. I would even suggest that we drop enforcement of this restriction during ATTACH. > Perhaps the ATTACH PARTITION text should be changed to make clear > which case it's talking about, say, like: > > If any of the CHECK constraints of the table being attached are marked > NO INHERIT, the command will fail if a constraint with the same name > exists in the parent table; such constraints must be recreated without > the NO INHERIT clause. Hmm, not sure about it; I think we're giving too much prominence to a detail that's not so important that it warrants four extra lines, when it could be a parenthical note next to the other mention of those constraints earlier in that paragraph. I suggest something like this: A partition using FOR VALUES uses same syntax for partition_bound_spec as CREATE TABLE. The partition bound specification must correspond to the partitioning strategy and partition key of the target table. The table to be attached must have all the same columns as the target table and no more; moreover, the column types must also match. Also, it must have all the NOT NULL and CHECK constraints of the target table. Currently FOREIGN KEY constraints are not considered. UNIQUE and PRIMARY KEY constraints from the parent table will be created in the partition, if they don't already exist. If any of the CHECK constraints of the table being attached are marked NO INHERIT, the command will fail; such constraints must be recreated without the NO INHERIT clause. I suggest we change it to A partition using FOR VALUES uses same syntax for partition_bound_spec as CREATE TABLE. The partition bound specification must correspond to the partitioning strategy and partition key of the target table. The table to be attached must have all the same columns as the target table and no more; moreover, the column types must also match. Also, it must have all the NOT NULL and CHECK constraints of the target table, not marked NO INHERIT. Currently FOREIGN KEY constraints are not considered. UNIQUE and PRIMARY KEY constraints from the parent table will be created in the partition, if they don't already exist. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "You don't solve a bad join with SELECT DISTINCT" #CupsOfFail https://twitter.com/connor_mc_d/status/1431240081726115845