I have this query in Postgres where I'm ordering a small amount of rows according to a varchar field. There seems to be an error in ordering UTF8 strings in Postgres:
For example:
'W' in UTF-8 is 87, while 'g' is 103, but running SELECT 'W' < 'g'; will return false while running SELECT convert_to('W', 'SQL_ASCII') < convert_to('g', 'SQL_ASCII')'; will return true.
The collation is en_US.UTF-8.
Is there a good explanation for this behavior? And how to avoid it?