pg_collkey
pg_collkey · ICU collation function wrapper
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100395 | pg_collkey | pg_collkey | 0.5.1 | UTIL | MIT | C |
PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18
Usage
Sources:
pg_collkey wraps ICU collation-key generation so a query can choose a locale and comparison strength independently of the database’s default collation. It is useful for producing sortable byte keys, including accent-insensitive or numeric-aware ordering, but the old upstream code supports only UTF-8 databases.
Core Workflow
Generate the key in ORDER BY or persist it in an expression index when the locale and options are stable:
The two-argument overload uses shifted punctuation handling, the default strength, and numeric sorting. The one-argument overload also selects the ICU root collation.
Important Objects
collkey(text, text, boolean, integer, boolean)returns an ICU sort key asbytea.- The locale argument selects ICU root or a named locale such as
fr_FR. - The first boolean shifts punctuation to the fourth comparison level.
- Strength 1 compares base characters; 2 includes accents; 3 includes case; 4 includes other differences; 5 compares normalized code points.
- The final boolean enables numeric ordering, so digit sequences sort by numeric value.
collkey(text, text)andcollkey(text)are convenience overloads.
Operational Notes
Sort keys are derived from the linked ICU library. ICU upgrades or locale-data changes can invalidate ordering assumptions and expression indexes, so reindex and regression-test results after such upgrades. Using many locales within one query adds setup cost. The README documents very old PostgreSQL and ICU baselines, and non-UTF-8 databases are unsupported.