BUG #6495: mis-sorting on string field consisting of space-padded numbers - Mailing list pgsql-bugs

From lou@paprikash.com
Subject BUG #6495: mis-sorting on string field consisting of space-padded numbers
Date
Msg-id E1S2I8G-0003fB-Uk@wrigleys.postgresql.org
Whole thread Raw
Responses Re: BUG #6495: mis-sorting on string field consisting of space-padded numbers
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      6495
Logged by:          Lou Duchez
Email address:      lou@paprikash.com
PostgreSQL version: 9.1.2
Operating system:   Fedora 16, CentOS 5
Description:=20=20=20=20=20=20=20=20

Download the following file and feed it into psql:

http://www.paprikash.com/lou/missorttest.sql

Then run the command:

select * from missorttest order by hiercode;

Each "hiercode" entry contains concatenations of numbers, where each number
is left-padded to take exactly four characters.  PostgreSQL is sorting as if
the padding were on the right.  As a result, "   2  10" is coming before "=
=20=20
2   2", even though a literal sorting of the string should put "   2   2"
first (because chr 32 comes before chr 49).

More info: this error does not occur on the Windows build of PostgreSQL.=20
Also, I compile my own versions of PostgreSQL on Fedora and CentOS, taking
all the defaults.

pgsql-bugs by date:

Previous
From: Robert Haas
Date:
Subject: Re: BUG #6456: no password
Next
From: Pavel Stehule
Date:
Subject: Re: BUG #6495: mis-sorting on string field consisting of space-padded numbers