Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1plbOJ-0004KA-1y for pgsql-hackers@arkaria.postgresql.org; Sun, 09 Apr 2023 20:11:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1plbOF-00066y-VU for pgsql-hackers@arkaria.postgresql.org; Sun, 09 Apr 2023 20:11:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1plbOF-00066p-Lp for pgsql-hackers@lists.postgresql.org; Sun, 09 Apr 2023 20:11:55 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1plbO8-001t7I-Or for pgsql-hackers@lists.postgresql.org; Sun, 09 Apr 2023 20:11:55 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 339KBgU73863450; Sun, 9 Apr 2023 16:11:42 -0400 From: Tom Lane To: Alvaro Herrera cc: Andres Freund , Justin Pryzby , Peter Eisentraut , pgsql-hackers@lists.postgresql.org Subject: Re: cataloguing NOT NULL constraints In-reply-to: <20230409191101.po3bjtxdvm562f4o@alvherre.pgsql> References: <20230409191101.po3bjtxdvm562f4o@alvherre.pgsql> Comments: In-reply-to Alvaro Herrera message dated "Sun, 09 Apr 2023 21:11:01 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3863448.1681071102.1@sss.pgh.pa.us> Date: Sun, 09 Apr 2023 16:11:42 -0400 Message-ID: <3863449.1681071102@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Alvaro Herrera writes: >> I'm inclined to think that this idea of suppressing the implied >> NOT NULL from PRIMARY KEY is a nonstarter and we should just >> go ahead and make such a constraint. Another idea could be for >> pg_dump to emit the NOT NULL, load data, do the ALTER ADD PRIMARY >> KEY, and then ALTER DROP NOT NULL. > I like that second idea, yeah. It might be tough to make it work, but > I'll try. Yeah, I've been thinking more about it, and this might also yield a workable solution for the TestUpgrade breakage. The idea would be, roughly, for pg_dump to emit NOT NULL column decoration in all the same places it does now, and then to drop it again immediately after doing ADD PRIMARY KEY if it judges that there was no other reason to have it. This gets rid of the inconsistency for --binary-upgrade which I think is what is causing the breakage. I also ran into something else I didn't much care for: regression=# create table foo(f1 int primary key, f2 int); CREATE TABLE regression=# create table foochild() inherits(foo); CREATE TABLE regression=# alter table only foo alter column f2 set not null; ERROR: cannot add constraint only to table with inheritance children HINT: Do not specify the ONLY keyword. Previous versions accepted this case, and I don't really see why we can't do so with this new implementation -- isn't this exactly what pg_constraint.connoinherit was invented to represent? Moreover, existing pg_dump files can contain precisely this construct, so blowing it off isn't going to be zero-cost. regards, tom lane