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 1t8wfM-006rkR-O9 for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Nov 2024 07:10:52 +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 1t8wfJ-00D12T-RQ for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Nov 2024 07:10:50 +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 1t8wfJ-00D12L-HR for pgsql-hackers@lists.postgresql.org; Thu, 07 Nov 2024 07:10:50 +0000 Received: from mail-ua1-x935.google.com ([2607:f8b0:4864:20::935]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1t8wfF-000dba-UW for pgsql-hackers@lists.postgresql.org; Thu, 07 Nov 2024 07:10:49 +0000 Received: by mail-ua1-x935.google.com with SMTP id a1e0cc1a2514c-84fc21ac668so233166241.1 for ; Wed, 06 Nov 2024 23:10:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730963445; x=1731568245; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=0vZZ3xzRkpzUA/uejSufcLknmzZRydcFs70V3JP+JfM=; b=AzqyWCLoSXg4iAaOhBgr5+ouGxPP4hwiBuaKOeU+1HW1hZaITFfirmdQ1/xEoubput s6XRG5MkHxcPJXbIKzG78Yg5lVLHUinsqv4ebQ0P8Fc98qyd3k+dTmkNN9xDvrfoXZ8N e1GcnVPcNqexKS0L5U+EXd6ZhnTGij2r65aUoeZR3/6VtnhcqZBGfHYiJiS945SGI9Hu vPWB40wjssXh1Z/jcaqY+S09ZYyijHoxLDh32myOFSrDDTcaEHCwLWWEVZUySNuTxwAt XSIUn8Oi5a0RGLGS70+a+8E7WJiU9vjsO/0hxQwOC/x9ZVtnRnFb0aN+r/HZhIPO/wQU EEAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730963445; x=1731568245; h=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=0vZZ3xzRkpzUA/uejSufcLknmzZRydcFs70V3JP+JfM=; b=huH0MgifWsm4mxEyQO1K4AcB3nyM0gfqMkG0QFqD6FHiAfpdSqrhY61y5cta981B+K /QVPmIjxsPW1Vp9xIj71mmJwal9+xZVs9wyPdWpvGCeZ10OVr92DBs1KTRyyhGPDY5gN eyAx21ZT/8cAym5uUkIWsIKZozZnvkeZECM4DZ+2GjG0h8WCYYkRQfDBdSGw2eA3IHSv 2OYmO+6TjgHgb1HLxGF/OFRTacd24TSHdbRUP0v2k+pUNeKxfIdWfwKBNSRIhAZr1v3Y PJVsb1o4P4+Jzb6D09wOOIethd5272hNgg/DNQJ34XxcPnBy2ORvzMvYq3syjoCYRj7w UvHA== X-Gm-Message-State: AOJu0YyMc6hpmuVqoEaR2JFETyA4bjaiHd4WByPDLfRhfOL/PC7/Ja3v sOL2mzOmmlPNTYWzmOYViJCz5SZKaSd2oHCcO26RIZoNskk2SvmnOwQebIW6wMbJQWzw9UPQSy4 y2njA9Kb9AVNS+EJlPfOwLSF/kvw= X-Google-Smtp-Source: AGHT+IG3ntFGMVt0mFOyMjTGD/mJO2lLKNnZIiAf2QkwSvKxpACREIhpemFMwEDuCJunFTXb0keHlP5ldGJ3xEhogbY= X-Received: by 2002:a05:6102:d8c:b0:498:f38a:2c80 with SMTP id ada2fe7eead31-4a8cfb4d1d9mr41250347137.10.1730963444852; Wed, 06 Nov 2024 23:10:44 -0800 (PST) MIME-Version: 1.0 References: <202410141606.ik7zylnocx3n@alvherre.pgsql> In-Reply-To: From: jian he Date: Thu, 7 Nov 2024 15:10:33 +0800 Message-ID: Subject: Re: not null constraints, again To: Alvaro Herrera Cc: Pg Hackers , Tender Wang Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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" 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. ------------------------------------------------ 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.