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 1t8W1J-004f4U-US for pgsql-hackers@arkaria.postgresql.org; Wed, 06 Nov 2024 02:43: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 1t8W1G-002hzp-D9 for pgsql-hackers@arkaria.postgresql.org; Wed, 06 Nov 2024 02:43:42 +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 1t8W1G-002hze-4K for pgsql-hackers@lists.postgresql.org; Wed, 06 Nov 2024 02:43:42 +0000 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1t8W1D-000OyX-UK for pgsql-hackers@lists.postgresql.org; Wed, 06 Nov 2024 02:43:41 +0000 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-72041ff06a0so5357704b3a.2 for ; Tue, 05 Nov 2024 18:43:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730861018; x=1731465818; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=zITPlSUgeFL2n/Xkg/42451Nczik+tNNhwzdWTw4atM=; b=fHC9XnAkP9Wzp8pWd35K9AfmoSva6X5FNRXhwh2Qoy/UWpRITfpn9iOBtxDJyWhWYb oBQ8f04k9MbA4eBb1QPKUO/cfxpUi2aSMEajDbMi7rkh2/c4TGZR9/zkE2EE2hzE32YB 8YPffs4avmt337sXHsMeKjdTbr+zNYVC7nvnV9Yhbn3WMLVCQ1bFYOj9tBgvtulcxP0A 7UM5a2VhaIT2i9O5tvHP2yf4a3JfgoM0wLDPTEFK++xwJA6X1dzwKgilVveeuJlxIxFq Pe2I02ioIrDxVPXu3HytrxlgYW5HzeUSjlKahn087zUNwXFqqxlR+KGVPJ5m1/E2N/k9 nBvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730861018; x=1731465818; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zITPlSUgeFL2n/Xkg/42451Nczik+tNNhwzdWTw4atM=; b=Ea7kUgAemy7efGfNvlazDeDDWPYzFDqRlBHL0WuT/yQchMY4HlAb/VwDugR6XcMWfM nCNoPmnbcMdxXcN4Y68nSmHP8Th2E1GouRbkBN3CWnf5anBlQ37rv/epR3sZBnYOHDqg neuwHEkOw+Vd7GDzwPJT6k75uL/L7V2sXkVMLFuL1cI9eX/CVsmZm/QFyQsfQNHZVOVz h32j8ajFzqrI5V25fHuplY3TNuYKhp1eXJoW4flI3QIqSqwVyiSN3MsUdXh9dJVRdTFx TW0AhCOol9XpeKRLDSBKKY0YHpJbTKtQwrmO9UnpwmStJ24EtL24JpBm26kQhfMX8rRe x4qg== X-Gm-Message-State: AOJu0Yx2+awvbTySTYHxonO2B2IEDeouWuyajjA2UrI4RWmM5Qs+aOHF 3LBpzCs6/hYAmPr5Vizv/KxLxwPlRrH5QvHyZG7CbjVfjEFZD2+WMiF6OCpqK1EjedqY48J3jlE UcJ5NE6ZnDzSCE3JgizAe9XigfGM= X-Google-Smtp-Source: AGHT+IHE4wrl5sZOaQpQrVH52E0z2SPrBoMOJ86rSwfZxBkiw+jUcT8JLhBZ9BqBkBcHjNrkKwITmPn7+7ZcjuEx3IY= X-Received: by 2002:a05:6a20:7290:b0:1db:eb91:56d6 with SMTP id adf61e73a8af0-1dbeb91576cmr9500169637.40.1730861018409; Tue, 05 Nov 2024 18:43:38 -0800 (PST) MIME-Version: 1.0 References: <202411051201.zody6mld7vkw@alvherre.pgsql> In-Reply-To: <202411051201.zody6mld7vkw@alvherre.pgsql> From: Amit Langote Date: Wed, 6 Nov 2024 11:43:22 +0900 Message-ID: Subject: Re: doc fail about ALTER TABLE ATTACH re. NO INHERIT To: Alvaro Herrera Cc: Pg Hackers , Robert Haas Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Alvaro, On Tue, Nov 5, 2024 at 9:01=E2=80=AFPM Alvaro Herrera wrote: > > Hello, > > 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 marke= d NO > INHERIT, the command will fail; such constraints must be recreated wi= thout the > NO INHERIT clause. > > However, this is not true and apparently has never been true. I tried > this in both master and pg10: > > create table parted (a int) partition by list (a); > create table part1 (a int , check (a > 0) no inherit); > alter table parted attach partition part1 for values in (1); > > In both versions (and I imagine all intermediate ones) that sequence > works fine and results in this table: > > Table "public.part1" > Column =E2=94=82 Type =E2=94=82 Collation =E2=94=82 Nullable =E2=94= =82 Default =E2=94=82 Storage =E2=94=82 Stats target =E2=94=82 Description > =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80 > a =E2=94=82 integer =E2=94=82 =E2=94=82 =E2=94= =82 =E2=94=82 plain =E2=94=82 =E2=94=82 > Partition of: parted FOR VALUES IN (1) > Partition constraint: ((a IS NOT NULL) AND (a =3D 1)) > Check constraints: > "part1_a_check" CHECK (a > 0) NO INHERIT > > On the other hand, if we were to throw an error in the ALTER TABLE as > the docs say, it would serve no purpose: the partition cannot have any > more descendants, so the fact that the CHECK constraint is NO INHERIT > makes no difference. So I think the code is fine and we should just fix > the docs. > > > Note that if you interpret it the other way around, i.e., that the > "table being attached" is the parent table, then the first CREATE > already fails: > > create table parted2 (a int check (a > 0) no inherit) partition by list (= a); > ERROR: cannot add NO INHERIT constraint to partitioned table "parted2" > > This says that we don't need to worry about this condition in the parent > table either. > > All in all, I think this text serves no purpose and should be removed > (from all live branches), as in the attached patch. 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" which is due to this code in MergeConstraintsIntoExisting(): /* If the child constraint is "no inherit" then cannot merge */ if (child_con->connoinherit) ereport(ERROR, (errcode(ERRCODE_INVALID_OBJECT_DEFINITION), errmsg("constraint \"%s\" conflicts with non-inherited constraint on child table \"%s\"", NameStr(child_con->conname), RelationGetRelationName(child_rel)))); that came in with the following commit: commit 3b11247aadf857bbcbfc765191273973d9ca9dd7 Author: Alvaro Herrera Date: Mon Jan 16 19:19:42 2012 -0300 Disallow merging ONLY constraints in children tables 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. --=20 Thanks, Amit Langote