Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 866009552CF for ; Tue, 28 Feb 2012 04:10:15 -0400 (AST) Received: from mahout.postgresql.org ([98.129.198.123]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S2I8U-0007Ka-JW for pgsql-bugs@postgresql.org; Tue, 28 Feb 2012 08:10:15 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S2I8H-0000AO-UX for pgsql-bugs@postgresql.org; Tue, 28 Feb 2012 08:10:02 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.72) (envelope-from ) id 1S2I8G-0003fB-Uk for pgsql-bugs@postgresql.org; Tue, 28 Feb 2012 08:10:00 +0000 Date: Tue, 28 Feb 2012 08:10:00 +0000 Message-Id: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #6495: mis-sorting on string field consisting of space-padded numbers To: pgsql-bugs@postgresql.org From: lou@paprikash.com X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201202/195 X-Sequence-Number: 32538 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: = 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 " = 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. = Also, I compile my own versions of PostgreSQL on Fedora and CentOS, taking all the defaults.