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 1p5Tow-0008Rw-Ab for pgsql-bugs@arkaria.postgresql.org; Wed, 14 Dec 2022 15:37:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p5Tou-0000OD-Sw for pgsql-bugs@arkaria.postgresql.org; Wed, 14 Dec 2022 15:37:20 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p5Tou-0000O4-LQ for pgsql-bugs@lists.postgresql.org; Wed, 14 Dec 2022 15:37:20 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p5Toq-00069e-LH for pgsql-bugs@lists.postgresql.org; Wed, 14 Dec 2022 15:37:19 +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 2BEFb2co2684952; Wed, 14 Dec 2022 10:37:03 -0500 From: Tom Lane To: Daniel Gustafsson cc: "David G. Johnston" , "zedaardv@drizzle.com" , "pgsql-bugs@lists.postgresql.org" Subject: Re: BUG #17720: pg_dump creates a dump with primary key that cannot be restored, when specifying 'using index ...' In-reply-to: <9C039DE3-EFBD-4D65-B4CF-90D8148B7B4C@yesql.se> References: <17720-dab8ee0fa85d316d@postgresql.org> <9C039DE3-EFBD-4D65-B4CF-90D8148B7B4C@yesql.se> Comments: In-reply-to Daniel Gustafsson message dated "Wed, 14 Dec 2022 14:02:40 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <2684950.1671032222.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 14 Dec 2022 10:37:02 -0500 Message-ID: <2684951.1671032222@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Daniel Gustafsson writes: > On 14 Dec 2022, at 13:54, David G. Johnston = wrote: >> There is a decent chance that the fix here is to prohibit doing what yo= u did here - a PK cannot contain nulls in any of its columns so indeed cho= osing an index that specifies how nulls behave is non-sensical. That said= , it also doesn=E2=80=99t hurt so long as the column itself is indeed not = null. But extending the syntax doesn=E2=80=99t seem that appealing. > Even if we prohibit this, there is still the case of all existing system= s which > can't be dumped. I wonder if the solution is to teach pg_dump to not cr= eate > NULLS NOT DISTINCT primary key constraints? The simple attached fix cre= ates a > valid PK constraint on the above schema. It doesn't make sense for pg_dump to editorialize on a schema that we otherwise consider valid; people would rightfully complain that dump/restore changed things. So we need to do both things: prohibit adopting such an index as a PK constraint (but I guess it's okay for plain unique constraints?), and adjust pg_dump to compensate for the legacy case where it was already done. regards, tom lane