Re: pg_dump losing index column collations for unique and primary keys

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alexey Bashtanov <bashtanov(at)imap(dot)cc>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: pg_dump losing index column collations for unique and primary keys
Date: 2019-12-03 19:52:13
Message-ID: 17844.1575402733@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Alexey Bashtanov <bashtanov(at)imap(dot)cc> 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(dot)1558909428(at)sss(dot)pgh(dot)pa(dot)us
If you'd like to help move things along by reviewing that patch,
it'd be great.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Stephen Frost 2019-12-03 19:58:12 Re: BUG #16079: Question Regarding the BUG #16064
Previous Message Alexey Bashtanov 2019-12-03 19:30:49 Re: pg_dump losing index column collations for unique and primary keys