postgresqlpostgresql-11

Why am I getting "collation attribute X not recognized" in my PostgreSQL database?


I'm running a PostgreSQL 11.22 database, and I want to create a new collation to support the Czech language, since I don't see it on the collations list when I select from pg_catalog.

Attempt 1 The documentation claims it is possible to create a collation basing it off of libc like so:

CREATE COLLATION czech (provider = libc, locale = 'cs_CZ'); But I got: ERROR: could not create locale "cs_CZ": No such file or directory
DETAIL: The operating system could not find any locale data for the locale name "cs_CZ".

Attempt 2 After that, I tried creating a custom collation, in which I could manually set the Czech language's collation rules, like so:

CREATE COLLATION IF NOT EXISTS czech (provider = icu, locale = 'und', rules = '...');

But I got the error

ERROR: collation attribute "rules" not recognized LINE 2: ...OT EXISTS custom (provider = icu, locale = 'und', rules = '...

Do I have an incorrect version of PostgreSQL? Is that a newer feature, or does something else need to be configured?


Solution

  • For the first question, you first have to make sure that the C library has a collation with that name for your current encoding. After you create or install new C library collations, you have to import them into PostgreSQL with

    SELECT pg_import_system_collations('pg_catalog');
    

    For the second question, the RULES clause does not exist in the unsupported version 11 of PostgreSQL.