PostgreSQL – Collate Example in SELECT Query

collationlikepostgresql

I would like to comprehend the different behavior of like and =. Sadly, I can not reproduce the following simple example thus that both queries return a different result:

SELECT 'ä' LIKE 'ae' COLLATE "de_DE.utf8"; 
SELECT 'ä' = 'ae' COLLATE "de_DE.utf8"; 

both return false.

What am I doing wrong?

Best Answer

PostgreSQL does not support = or LIKE on COLLATE. This is because internally index ordering uses = and so even if the collation returns that they're equal PostgreSQL falls back to binary equal. This is documented,

Note that while this system allows creating collations that “ignore case” or “ignore accents” or similar (using the ks key), PostgreSQL does not at the moment allow such collations to act in a truly case- or accent-insensitive manner. Any strings that compare equal according to the collation but are not byte-wise equal will be sorted according to their byte values.

PostgreSQL also doesn't support Unicode collation in character classes.