Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1icEDk-0003Kh-BT for pgsql-bugs@arkaria.postgresql.org; Tue, 03 Dec 2019 19:52:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1icEDi-0005vM-L7 for pgsql-bugs@arkaria.postgresql.org; Tue, 03 Dec 2019 19:52:26 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1icEDi-0005vE-4w for pgsql-bugs@lists.postgresql.org; Tue, 03 Dec 2019 19:52:26 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1icEDa-0000I9-G4 for pgsql-bugs@postgresql.org; Tue, 03 Dec 2019 19:52:24 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id xB3JqDP1017845; Tue, 3 Dec 2019 14:52:13 -0500 From: Tom Lane To: Alexey Bashtanov cc: pgsql-bugs@postgresql.org Subject: Re: pg_dump losing index column collations for unique and primary keys In-reply-to: References: <13713.1575392277@sss.pgh.pa.us> <6484.1575397478@sss.pgh.pa.us> Comments: In-reply-to Alexey Bashtanov message dated "Tue, 03 Dec 2019 19:30:49 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <17843.1575402733.1@sss.pgh.pa.us> Date: Tue, 03 Dec 2019 14:52:13 -0500 Message-ID: <17844.1575402733@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alexey Bashtanov writes: >> In short, I'd say the bug here is not pg_dump's fault at all, >> but failure to insist on collation match in ADD PRIMARY KEY >> USING INDEX. > While being entirely reasonable especially with the non-deterministic > collations, > this breaks down an important facility of changing a column collation > without > rewriting it even if it is a part of a unique constraint: first change > the PK then the > column itself. Well, I disagree that that's a high-priority use case, but it seems to me that you can still do it. You just can't call the index the pkey until the column collation agrees. So roughly it'd be * CREATE UNIQUE INDEX ... (col COLLATE new-collation) * Drop old pkey (the new index is still enforcing uniqueness) * ALTER TABLE ... ALTER COLUMN ... COLLATE new-collation * ALTER TABLE ADD PRIMARY KEY USING INDEX These seem to me to be pretty much exactly the same steps you'd need today, although maybe the current code is more forgiving about their ordering. > Disallowing changing the direction (ASC/DESC) also looks cruel to me. That restriction has been there since day one, and we have had a grand total of zero complaints about it. > BTW with playing with this stuff I came across another issue, > which seems unrelated to collations: Yeah, see https://www.postgresql.org/message-id/flat/10365.1558909428@sss.pgh.pa.us If you'd like to help move things along by reviewing that patch, it'd be great. regards, tom lane