Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id E3E40B5DBC5 for ; Wed, 22 Jun 2011 05:46:30 -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 00109-06 for ; Wed, 22 Jun 2011 08:46:24 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-iy0-f174.google.com (mail-iy0-f174.google.com [209.85.210.174]) by mail.postgresql.org (Postfix) with ESMTP id 65282B5DBE1 for ; Wed, 22 Jun 2011 05:46:24 -0300 (ADT) Received: by iyb12 with SMTP id 12so494369iyb.19 for ; Wed, 22 Jun 2011 01:46:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type:content-transfer-encoding; bh=CsMuTZYZWRDnYh2iDXVvsEUIXveaqzj+e6bT7+26o5k=; b=Dc9QF1RTyKdhPbjCm/EbHwrHxyFw27zEea+K2q4AhHh9lcungikbBv1GhaI0RAXdfg qb436CW0IAO31AkO/O2ac1Wy7jYgkKg01aTmUCVqbdtDLg1062OixtDUSu6gDxVlDU21 4Q+NLMbXh1xb8VHnjr9oWS8zhwvMhK7J1KfjU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=bQaKrHbMF86+JuJvLR96UHrktC06J5gYLy9rCw9chnGmXD/yVL8v2x5XKbAkKTNODu gMCaFJivhZjKvNoLPZYyoZfaycknWV8TEAdXBIDZ59S7PQoToOXXBBdmiULlBMFMcmDJ X/1cxphIOo8hBvUadKfaN2SeD8flMsQtNpWTk= Received: by 10.42.157.72 with SMTP id c8mr451745icx.401.1308732384101; Wed, 22 Jun 2011 01:46:24 -0700 (PDT) MIME-Version: 1.0 Received: by 10.42.1.141 with HTTP; Wed, 22 Jun 2011 01:45:44 -0700 (PDT) In-Reply-To: References: From: Pavel Stehule Date: Wed, 22 Jun 2011 10:45:44 +0200 Message-ID: Subject: Re: a strange order by behavior To: Samuel Gendler Cc: Eyal Wilde , pgsql-sql@postgresql.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.898 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RFC_ABUSE_POST=0.001 X-Spam-Level: X-Archive-Number: 201106/76 X-Sequence-Number: 35542 Hello a equalent of C collate for UTF8 is ucs_basic Regards Pavel Stehule 2011/6/22 Samuel Gendler : > > > On Tue, Jun 21, 2011 at 3:37 AM, Eyal Wilde wrote= : >> >> the database collation is: en_US.UTF-8 >> drop table t1; >> create table t1 (recid int ,f1 varchar(20)); >> insert into t1 values (1,'a'); >> insert into t1 values (2,' '); >> insert into t1 values (3,'aa'); >> insert into t1 values (4,' a'); >> select * from t1 order by f1 >> result: >> recid =C2=A0f1 >> 2 =C2=A0 =C2=A0 =C2=A0" " >> 1 =C2=A0 =C2=A0 =C2=A0"a" =C2=A0 =C2=A0 =C2=A0 =C2=A0-- 2 comes before 1= because space is smaller then 'a'. >> fine. >> 4 =C2=A0 =C2=A0 =C2=A0" a" =C2=A0 =C2=A0 =C2=A0 -- now is see that 1 com= es before 4 because space is >> greater then 'a' !? >> 3 =C2=A0 =C2=A0 =C2=A0"aa" =C2=A0 =C2=A0 =C2=A0 -- now again, 4 comes be= fore 3 because space is smaller >> the 'a' !?! > > I seem to recall a thread here about it ignoring spaces entirely in that > collation (and maybe ignoring capitalization, too?). =C2=A0I went to go t= est that > assertion by initializing a database with C collation and got some compla= int > about it being incompatible with my template1 template database. =C2=A0I > initialized a db off of template0 and then got side tracked and you've on= ly > just reminded me of it. =C2=A0I was planning to test whether it is safe t= o use > UTF-8 for encoding but use C collation, and then maybe investigate other > collations. > This worked: > createdb =C2=A0-E UTF-8 --lc-collate=3DC some_db > so it should be easy enough to play around with it some. =C2=A0I'm not su= re how > to get a list of valid collations for any given charset, and it seems lik= e C > collation would generate somewhat strange results with non-ascii characte= rs > (french accented characters are supposed to alphabetize in some unexpecte= d > manner, I believe), so there must be something better - closer to UTF-8 > collation but without ignoring whitespace and such. =C2=A0A quick google = search > reveals that there is some kind of standard for unicode collation > (http://www.unicode.org/reports/tr10/ ) and I have no idea if that is wha= t > is represented by the en_US.UTF-8 collation or not. =C2=A0I've got no rea= l > experience with this stuff. > It appears that there are differences regarding collation in recent versi= ons > - the beta docs for 9.1 show that you can set collation on individual > operations or differently for different columns > (http://www.postgresql.org/docs/9.1/static/collation.html ). =C2=A0I see = nothing > like that in 8.4 docs. > It definitely looks like we both need to have a read of the localization > chapter of the docs for our database version as there is a bunch of stuff= in > there that I was surprised to read when I just did a quick scan - like us= ing > anything but C or posix is much slower and can produce incorrect results = in > a 'like' query > It looks like the docs prior to 9.1beta have no real reference to collati= on > at all, so it's down to trial and error unless someone in the know speaks > up. > --sam > >