Re: sorting goofiness

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Hal Roberts <hroberts(at)cyber(dot)law(dot)harvard(dot)edu>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: sorting goofiness
Date: 2002-04-01 19:47:19
Message-ID: 20020401114400.W51949-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 1 Apr 2002, Hal Roberts wrote:

> h2o_hroberts=# select ''''||foo||'''' as foo from bar order by foo;
> foo
> -----------------------
> 'a'
> 'a a'
> 'aaa'
> 'a b'
> 'ab '
> 'abb'
> 'a l'
> 'a l'
> 'alyxbqu lynscw gshi'
> 'a n'
> 'a n'
> 'an'
> 'a nkp'
> 'ann'
> 'a o'
> 'b'
> 'bb b'
> 'bbbb'
> (18 rows)
> ****
>
> "foo" is just a text field. The determination of whether a string with
> a space at a given location should be sorted before a string with
> non-space at the same location seems to depend on a number of variables
> including the total length of the string and the character following the
> space. In my elementary school career, I learned that a space should
> always sort before a non-space.
>
> Am I missing something here ?

You're probably using a locale other than C (such as en_US if you're in
the US) which has different sorting rules. If you put the above data
in a text file and do commands like:
sort file
LANG="C" sort file
LANG="en_US" sort file

You'll see differences in the sort order.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David Esposito 2002-04-01 20:43:15 Core dump on PG 7.1.3
Previous Message Nic Ferrier 2002-04-01 19:46:55 Re: NOT IN queries