X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id E10F09FA3AD for ; Wed, 7 Jun 2006 18:16:28 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 79879-03 for ; Wed, 7 Jun 2006 18:16:17 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 973269FA2E6 for ; Wed, 7 Jun 2006 18:16:17 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k57LGEsi017523; Wed, 7 Jun 2006 17:16:14 -0400 (EDT) To: Ivan Voras cc: pgsql-performance@postgresql.org Subject: Re: Curious sorting puzzle In-reply-to: <4487285A.5050104@fer.hr> References: <4487285A.5050104@fer.hr> Comments: In-reply-to Ivan Voras message dated "Wed, 07 Jun 2006 21:26:18 +0200" Date: Wed, 07 Jun 2006 17:16:13 -0400 Message-ID: <17522.1149714973@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/80 X-Sequence-Number: 19437 Ivan Voras writes: > The situation is this: we're using a varchar column to store > alphanumeric codes which are by themselves 7-bit clean. But we are > operating under a locale which has its own special collation rules, and > is also utf-8 encoded. Recently we've discovered a serious "d'oh!"-type > bug which we tracked down to the fact that when we sort by this column > the collation respects locale sorting rules, which is messing up other > parts of the application. > The question is: what is the most efficient way to solve this problem > (the required operation is to sort data using binary "collation" - i.e. > compare byte by byte)? Since this field gets queried a lot it must have > an index. Some of the possible solutions we thought of are: replacing > the varchar type with numeric and do magical transcoding (bad, needs > changes thoughout the application) and inserting spaces after every > character (not as bad, but still requires modifying both the application > and the data). An ideal solution would be to have a > "not-locale-affected-varchar" field type :) If you're just storing ASCII then I think bytea might work for this. Do you need any actual text operations (like concatenation), or this just a store-and-retrieve field? If you need text ops too then probably the best answer is to make your own datatype. It's not that hard --- look at the citext datatype (on pgfoundry IIRC, or else gborg) for a closely related example. regards, tom lane