Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 7EF3D632989 for ; Mon, 19 Jul 2010 11:11:55 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 02515-03 for ; Mon, 19 Jul 2010 14:11:46 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from gw.wicourts.gov (gwmta.wicourts.gov [165.219.244.99]) by mail.postgresql.org (Postfix) with ESMTP id E2146632944 for ; Mon, 19 Jul 2010 11:11:47 -0300 (ADT) Received: from Courts-MTA by gw.wicourts.gov with Novell_GroupWise; Mon, 19 Jul 2010 09:11:46 -0500 Message-Id: <4C4416CB020000250003389C@gw.wicourts.gov> X-Mailer: Novell GroupWise Internet Agent 8.0.1 Date: Mon, 19 Jul 2010 09:11:39 -0500 From: "Kevin Grittner" To: , "Robert Voinea" Subject: Re: Weird sorting order References: <201007161514.09960.robert.voinea@topex.ro> <4C40359E0200002500033711@gw.wicourts.gov> <201007190823.14092.robert.voinea@topex.ro> In-Reply-To: <201007190823.14092.robert.voinea@topex.ro> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.311 tagged_above=-10 required=5 tests=BAYES_20=-0.001, RCVD_IN_DNSWL_MED=-2.3, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201007/135 X-Sequence-Number: 35154 Robert Voinea wrote: > => show lc_collate; > lc_collate > ------------- > en_US.UTF-8 I'm afraid the order you're seeing is what you're supposed to get for that collation sequence. In that collation, special characters (including spaces) are only used as tie-breakers for values which are tied when the special characters are ignored. There may be a few consequences of that which you haven't yet found. As one example: test=# show lc_collate; lc_collate ------------- en_US.UTF-8 (1 row) test=# create table t1 (c1 text); CREATE TABLE test=# insert into t1 values ('one'),(' one'),('one '),('##one'),('one##'); INSERT 0 5 test=# select '"' || c1 || '"' from t1 order by c1; ?column? ---------- "one" " one" "##one" "one " "one##" (5 rows) test=# select '"' || c1 || '"' from t1 order by c1 desc; ?column? ---------- "one##" "one " "##one" " one" "one" (5 rows) For that reason, we have (so far) used the C locale, which provides the binary sort you probably expected, and we use special columns, maintained by triggers, to control selection and sequencing as needed -- for example we have a "searchName" column in any table where we have name columns, which is forced into a canonical format. FWIW, our algorithm for generating a canonical name also excludes spaces and the '#' character, although it still has significant differences from the en_US.UTF-8 collation. -Kevin