problem with sorting using 'ORDER BY' when character field is filled with numerical values - Mailing list pgsql-general

From Dragan Matic
Subject problem with sorting using 'ORDER BY' when character field is filled with numerical values
Date
Msg-id 40ACC57B.1010809@panforma.co.yu
Whole thread Raw
Responses Re: problem with sorting using 'ORDER BY' when character  (Guy Fraser <guy@incentre.net>)
Re: problem with sorting using 'ORDER BY' when character  (Dave Smith <dave.smith@candata.com>)
Re: problem with sorting using 'ORDER BY' when character  (Dave Smith <dave.smith@candata.com>)
Re: problem with sorting using 'ORDER BY' when character  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
Re: problem with sorting using 'ORDER BY' when character field is filled with numerical values  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
If I have a table t with column c which is defined as char(5) and fill
it with following values:

insert into t (c) values ('    1')
insert into t (c) values ('    2')
insert into t (c) values ('    3')
insert into t (c) values ('    4')
insert into t (c) values ('   11')
insert into t (c) values ('   12')
insert into t (c) values ('   14')
insert into t (c) values ('   24')
insert into t (c) values ('   21')
insert into t (c) values ('   31')
insert into t (c) values ('  333')

and then do the following: SELECT C FROM T ORDER BY C
Postgres gives me the following

    1
   11
   12
   14
    2
   21
   24
    3
   31
  333
    4

the same thing done with MS SQL server gives this as a result:

    1
    2
    3
    4
   11
   12
   14
   21
   24
   31
  333

which is the result I find more logical, meaning the user would expect
data sorted this way. Is there some way to make Postgres sort elements
in this way (setting sort order or collation, I suppose)? Tnx in advance

Dragan




pgsql-general by date:

Previous
From: Ken Godee
Date:
Subject: Re: list of open connections / terminate a connection?
Next
From: "Bob Powell"
Date:
Subject: backend terminated abnormally