4
SELECT vm.value FROM vm ORDER BY vm.value ASC;

results in:

.
0
0%
0.0
0.964
%.0f
%.0f mph
-1.0°
11/1
11-14-1981
112 mph
11:48:43
%1$.1f mph %2$@
1/2
12.5˚
1/4
195 lb
%.1f°
2 days ago
%.2f
2º out-in
3/4
3.5
3.6
3D
3 days ago
4º closed
5'10''
5”10”
Account

I can remember that ASCII/Unicode digits should follow each other tightly not alternated with percents and other characters.

7
  • 2
    Looks like percents, dots and other special characters are just ignored during comparison. Commented Feb 21, 2013 at 19:15
  • 1
    What is the column type of vm.value? Commented Feb 21, 2013 at 19:16
  • @Joachim Isaksson: character varying(1000) Commented Feb 21, 2013 at 19:19
  • As ordering is governed by your locale, What is your locale set to? Try switching to the C locale and see if that changes it. Commented Feb 21, 2013 at 19:21
  • I thought that ORDER BY should be universal, locale-independent as is the Unicode itself. BTW: how to change/view locale? Commented Feb 21, 2013 at 19:25

1 Answer 1

6

I can remember that ASCII/Unicode digits should follow each other tightly not alternated with percents and other characters.

This applies to some locales but not others. Obviously it doesn't apply to the one you're using. Issue show lc_collate in SQL to see what locale is in use.

With recent versions of PG, including 9.1, you may use a per-query specific locale to sort, like this:

SELECT vm.value FROM vm ORDER BY vm.value COLLATE "C";

For the specific data shown in the question, this would sort as you expect.

Sign up to request clarification or add additional context in comments.

3 Comments

en_US.UTF-8 sorts in the manner the question describes. One would think that collation wouldn't disregard non alphanumerics.
Yes, I am using en_US.UTF-8
@JoachimIsaksson Where is en_US.UTF-8 collation order documented?

Your Answer

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.