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 1ryLyn-00Fpdt-FN for pgsql-hackers@arkaria.postgresql.org; Sun, 21 Apr 2024 01:26:53 +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 1ryLxo-00CdHe-4o for pgsql-hackers@arkaria.postgresql.org; Sun, 21 Apr 2024 01:25:52 +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 1ryLxn-00CdHW-RK for pgsql-hackers@lists.postgresql.org; Sun, 21 Apr 2024 01:25:51 +0000 Received: from charmander.telsasoft.com ([50.244.222.1] helo=pryzbyj2023.telsasoft) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ryLxl-003qUI-HV for pgsql-hackers@lists.postgresql.org; Sun, 21 Apr 2024 01:25:50 +0000 Received: by pryzbyj2023.telsasoft (Postfix, from userid 1000) id 052D32D03; Sat, 20 Apr 2024 20:25:49 -0500 (CDT) Date: Sat, 20 Apr 2024 20:25:48 -0500 From: Justin Pryzby To: Alvaro Herrera Cc: Andrew Dunstan , pgsql-hackers@lists.postgresql.org Subject: Re: pgsql: Fix restore of not-null constraints with inheritance Message-ID: References: <3a642a59-e3c7-4050-95dd-af3b5412e5f7@dunslane.net> <202404191159.cakeaydac4sq@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202404191159.cakeaydac4sq@alvherre.pgsql> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Apr 19, 2024 at 01:59:31PM +0200, Alvaro Herrera wrote: > BTW because of a concern from Justin that the NO INHERIT stuff will > cause errors in old server versions, I started to wonder if it wouldn't > be better to add these constraints in a separate line for compatibility, > so for example in the table above it'd be > > CREATE TABLE public.rule_and_refint_t2 ( > id2a integer, > id2c integer > ); > ALTER TABLE public.rule_and_refint_t2 ADD CONSTRAINT pgdump_throwaway_notnull_0 NOT NULL id2a NO INHERIT; > ALTER TABLE public.rule_and_refint_t2 ADD CONSTRAINT pgdump_throwaway_notnull_1 NOT NULL id2c NO INHERIT; > > which might be less problematic in terms of compatibility: you still end > up having the table, it's only the ALTER TABLE that would error out. Under pg_restore -d, those would all be run in a single transactional command, so it would *still* fail to create the table... It seems like the workaround to restore into an old server version would be to run: | pg_restore -f- |sed 's/ NO INHERIT//' |psql Putting them on separate lines makes that a tiny bit better, since you could do: | pg_restore -f- |sed '/^ALTER TABLE .* ADD CONSTRAINT .* NOT NULL/{ s/ NO INHERIT// }' |psql But I'm not sure whether that's enough of an improvement to warrant the effort. -- Justin