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 1rzrDN-007NDC-SG for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Apr 2024 05:00:09 +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 1rzrDM-00339c-04 for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Apr 2024 05:00:08 +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 1rzrDL-00339U-Ma for pgsql-hackers@lists.postgresql.org; Thu, 25 Apr 2024 05:00:07 +0000 Received: from mail-lf1-x12b.google.com ([2a00:1450:4864:20::12b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rzrDH-002pLA-M8 for pgsql-hackers@lists.postgresql.org; Thu, 25 Apr 2024 05:00:06 +0000 Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-518a56cdbcfso699325e87.2 for ; Wed, 24 Apr 2024 22:00:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714021202; x=1714626002; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=9Eo4Xb01jLAsZgxY+QLpiQnkqCZScZn1Or3wPNrxDpw=; b=aEmM4Dft+oluHWBXop/hdreoHhToxHgip22HS8Ln4e4I41b5sLhv+g5wqjaKiRxSic gjJl9pbb8E6CllVSghEiVR0jRX6uKPbF2FgVKV9hCEPCVaCnAkIq0ucTqZyabaMcG75a wY9g7yfnoLapGAmE3aF2LGzbrbsV3QAsfjrT/ADtAL2ogvkcS4KaNTtVev+Cbc0RIToA WHRmB8Pb/56wfYlqR6zqg/JR8RwrU8q5Z8Dn08yrBKne+Ro6UuxPKnJ6x4KucRUxENel YQRtPjus/R4th+01BO2/ML7iTxJSgPj71jm/fclW3pCWOeolcIkOFksAztCzw+sODF1Q ua4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714021202; x=1714626002; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9Eo4Xb01jLAsZgxY+QLpiQnkqCZScZn1Or3wPNrxDpw=; b=j5J11ZOYgca/WytcOfj12h6/VkRt3oocKhPyMf+crKrxTGEiGPHOrmHmOX260TDIiu 4t9I2Rq1hp2xTELmTX5XBeAUVgRR5Gf8Hw57H4CUP1vH1GvAYE8R6sLdi/LVbh5VT883 3fF1Lwnk9Z6EKDvD5kaLO/rZDvGyaTUgKtQZx/KDpAYWwEsZZN6dQ/SR6/z0JPxChRTH ibGCkEWiapM+Jw8U4euirBC7Lj7m78sT6AXGaWjbzppw3U5DcNExJRRuRaib05oqNIUJ bgmBJbsQ+FgGC6X8vX9W1kOv5skE2P0o2WH1EOtkJ3Mz0F74GGd+3LF1srj+8fFTtQBu Tjlg== X-Forwarded-Encrypted: i=1; AJvYcCVG08YpsEqtqcK/dR89dwMwx3EHIwJaEvTaOM1wxWCZSs3LIqRraU/w9KJ6txAqqvXvIfWQmDiM7Q9s75ARAcgEw4QceH0g7M+lbNh6hpiLu+hj X-Gm-Message-State: AOJu0YwhpMP92vNF50uqww2X2rBpffdAoSSBUxB2ecgO0UfKNP9tS7fb IFwEQq1y0ZvgTrb9ZnqpVP94WmHhArSCMGM+NGdYeKmiGqBpSRAdIM17kEFI X-Google-Smtp-Source: AGHT+IGVh64zRkTVd/6VujP/8Sh1ZuJIiGByXcrmWmcMnDQgy8Zp40pDtEW3FydOn52TFjNhs0NnWA== X-Received: by 2002:ac2:488f:0:b0:519:60da:56fa with SMTP id x15-20020ac2488f000000b0051960da56famr3623067lfc.42.1714021201747; Wed, 24 Apr 2024 22:00:01 -0700 (PDT) Received: from [1.0.0.7] ([178.155.19.141]) by smtp.gmail.com with ESMTPSA id s8-20020a197708000000b00516cef1f1casm2704928lfc.181.2024.04.24.22.00.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 Apr 2024 22:00:01 -0700 (PDT) Message-ID: <7d923a66-55f0-3395-cd40-81c142b5448b@gmail.com> Date: Thu, 25 Apr 2024 08:00:00 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: cataloguing NOT NULL constraints Content-Language: en-US To: Alvaro Herrera Cc: Dean Rasheed , Andrew Bille , Peter Eisentraut , Robert Haas , pgsql-hackers@lists.postgresql.org References: <202404241736.jf2zq2qmrgov@alvherre.pgsql> From: Alexander Lakhin In-Reply-To: <202404241736.jf2zq2qmrgov@alvherre.pgsql> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 24.04.2024 20:36, Alvaro Herrera wrote: > So I added a restriction that we only accept such a change when > recursively adding a constraint, or during binary upgrade. This should > limit the damage: you're no longer able to change an existing constraint > from NO INHERIT to YES INHERIT merely by doing another ALTER TABLE ADD > CONSTRAINT. > > One thing that has me a little nervous about this whole business is > whether we're set up to error out where some child table down the > hierarchy has nulls, and we add a not-null constraint to it but fail to > do a verification scan. I tried a couple of cases and AFAICS it works > correctly, but maybe there are other cases I haven't thought about where > it doesn't. > Thank you for the fix! While studying the NO INHERIT option, I've noticed that the documentation probably misses it's specification for NOT NULL: https://www.postgresql.org/docs/devel/sql-createtable.html where column_constraint is: ... [ CONSTRAINT constraint_name ] { NOT NULL |   NULL |   CHECK ( expression ) [ NO INHERIT ] | Also, I've found a weird behaviour with a non-inherited NOT NULL constraint for a partitioned table: CREATE TABLE pt(a int NOT NULL NO INHERIT) PARTITION BY LIST (a); CREATE TABLE dp(a int NOT NULL); ALTER TABLE pt ATTACH PARTITION dp DEFAULT; ALTER TABLE pt DETACH PARTITION dp; fails with: ERROR:  relation 16389 has non-inherited constraint "dp_a_not_null" Though with an analogous check constraint, I get: CREATE TABLE pt(a int, CONSTRAINT nna CHECK (a IS NOT NULL) NO INHERIT) PARTITION BY LIST (a); ERROR:  cannot add NO INHERIT constraint to partitioned table "pt" Best regards, Alexander