Question

I had this query:

SELECT * FROM table ORDER BY label ASC;

Since the labels are not in English, they didn't get sorted in the right order (ones beginning with "ö" were not in the bottom/end).

I therefore tried:

SELECT * FROM table ORDER BY label COLLATE "sv-SE" ASC;
SELECT * FROM table ORDER BY label COLLATE "sv_SE" ASC;

These gave errors about those collations not existing, which baffled me.

After a bunch of searching, I figured out to do:

SELECT * FROM pg_collation;

Which revealed that it's supposed to be:

sv-SE-x-icu

It worked when I used that identifier, but what's with the "-x-icu" stuff? What's that all about? I hate that they always have to mess with the standard locale identifiers so you can never rely on just the standard "language_location" format.

No correct solution

OTHER TIPS

The documentation, 23.2. Collation Support / 23.2.2.2.2. ICU Collations , states:

Collations provided by ICU are created in the SQL environment with names in BCP 47 language tag format, with a “private use” extension -x-icu appended, to distinguish them from libc locales.

 

ICU is the "International Components for Unicode", which, according to their homepage, is:

ICU is a mature, widely used set of C/C++ and Java libraries providing Unicode and Globalization support for software applications. ICU is widely portable and gives applications the same results on all platforms and between C/C++ and Java software.

ICU is released under a nonrestrictive open source license that is suitable for use with both commercial software and with other open source or free software.

Unicode is a specification, not software, hence for many years each vendor has implemented it on their own and thus there is not nearly as much consistency anyone working with collations would appreciate. The ICU project is, quite fortunately, being implemented by more and more vendors, which is improving Unicode support and consistency. If available, I would expect the ICU collations to be a better choice than non-ICU collations.

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top