1

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?

Evan Carroll
65.7k50 gold badges259 silver badges511 bronze badges
asked Jan 16, 2018 at 13:55
4
  • 1
    I don't think de_DE.utf8 has any rules about the fact that ä and ae should be considered equivalent. If at all, this might be possible with an ICU collation (but I don't know): postgresql.org/docs/current/static/… Commented Jan 16, 2018 at 14:06
  • I sadly haven't compiled my postgres with ICU support. This means that without ICU collation, like and = behave identical, if no wildcards are used? Commented Jan 16, 2018 at 14:37
  • 1
    This other answer has useful information: stackoverflow.com/a/11007216/6368697 pointing to the unaccent module. Commented Jan 16, 2018 at 15:15
  • @PatrickMevzek But note that unaccent() cannot help with 'ä' = 'ae'. It can help with 'ä' = 'a'. Commented Sep 8, 2022 at 23:16

1 Answer 1

1

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.

answered Sep 13, 2018 at 16:33
1
  • 2
    This is changed in PostgreSQL 12. See the updated documentation about "nondeterministic collations". Commented Sep 24, 2019 at 7:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.