Subject: pgsql: Allow tailoring of ICU locales with custom rules

From: Peter Eisentraut <[email-masked]>
Date: Wed, 08 Mar 2023 16:03:22 +0000

Allow tailoring of ICU locales with custom rules

This exposes the ICU facility to add custom collation rules to a
standard collation.

New options are added to CREATE COLLATION, CREATE DATABASE, createdb,
and initdb to set the rules.

Reviewed-by: Laurenz Albe <[email-masked]>
Reviewed-by: Daniel Verite <[email-masked]>
Discussion: https://www.postgresql.org/message-id/flat/[email-masked]

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/30a53b792959b36f07200dae246067b3adbcc0b9

Modified Files
--------------
doc/src/sgml/catalogs.sgml                     |  18 +++++
doc/src/sgml/ref/create_collation.sgml         |  22 ++++++
doc/src/sgml/ref/create_database.sgml          |  14 ++++
doc/src/sgml/ref/createdb.sgml                 |  10 +++
doc/src/sgml/ref/initdb.sgml                   |  10 +++
src/backend/catalog/pg_collation.c             |   5 ++
src/backend/commands/collationcmds.c           |  23 +++++-
src/backend/commands/dbcommands.c              |  51 ++++++++++++-
src/backend/utils/adt/pg_locale.c              |  41 +++++++++-
src/backend/utils/init/postinit.c              |  11 ++-
src/bin/initdb/initdb.c                        |  15 +++-
src/bin/pg_dump/pg_dump.c                      |  37 +++++++++
src/bin/psql/describe.c                        | 100 ++++++++++++++++---------
src/bin/scripts/createdb.c                     |  11 +++
src/include/catalog/catversion.h               |   2 +-
src/include/catalog/pg_collation.h             |   2 +
src/include/catalog/pg_database.dat            |   2 +-
src/include/catalog/pg_database.h              |   3 +
src/include/utils/pg_locale.h                  |   1 +
src/test/regress/expected/collate.icu.utf8.out |  30 ++++++++
src/test/regress/expected/psql.out             |  18 ++---
src/test/regress/sql/collate.icu.utf8.sql      |  13 ++++
22 files changed, 380 insertions(+), 59 deletions(-)

---

From: Jeff Davis <[email-masked]>
Date: Wed, 08 Mar 2023 12:57:29 -0800

> Allow tailoring of ICU locales with custom rules

Late review:

* Should throw error when provider != icu and rules != NULL

* Explain what the example means. By itself, users might get confused
wondering why someone would want to do that.

* Also consider a more practical example?

* It appears rules IS NULL behaves differently from rules=''. Is that
desired? For instance:
  create collation c1(provider=icu,
    locale='und-u-ka-shifted-ks-level1',
    deterministic=false);
  create collation c2(provider=icu,
    locale='und-u-ka-shifted-ks-level1',
    rules='',
    deterministic=false);
  select 'a b' collate c1 = 'ab' collate c1; -- true
  select 'a b' collate c2 = 'ab' collate c2; -- false

* Can you document the interaction between locale keywords
("@colStrength=primary") and a rule like '[strength 2]'?

Regards,
	Jeff Davis