From oliveiros.cristina@marktest.pt Wed Oct 14 14:13:34 2009 Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id D34FD633AB9 for ; Wed, 14 Oct 2009 11:13:34 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 84056-03 for ; Wed, 14 Oct 2009 14:13:26 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from jupiter.marktest.pt (delta.marktest.pt [80.251.174.116]) by mail.postgresql.org (Postfix) with ESMTP id EC1FF6339AB for ; Wed, 14 Oct 2009 11:13:26 -0300 (ADT) Received: from Proteu (proteu.marktest.pt [10.61.90.54]) by jupiter.marktest.pt with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id 4R8TJC85; Wed, 14 Oct 2009 15:13:23 +0100 Message-ID: <99F66F53142145DE8127EAF7423AF726@marktestcr.marktest.pt> From: "Oliveiros C," To: References: <6caee9520910140240u13daba93ua20637642727776e@mail.gmail.com> Subject: How to order varchar data by word Date: Wed, 14 Oct 2009 15:13:22 +0100 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_002E_01CA4CE0.DED5A890" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5512 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.002 tagged_above=-10 required=5 tests=BAYES_50=0.001, HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200910/58 X-Sequence-Number: 33257 This is a multi-part message in MIME format. ------=_NextPart_000_002E_01CA4CE0.DED5A890 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hello, list. I have a table with a varchar field that I would like to order by word, = not by ordinal, which seems to be the default on postgres. Does anyone have a clue on how this can be done? Many thanx in advance, Best, Oliveiros ------=_NextPart_000_002E_01CA4CE0.DED5A890 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
 Hello, list.
 
I have a table with a varchar field = that I would=20 like to order by word, not by ordinal, which seems to be the default on=20 postgres.
 
Does anyone have a clue on how this can = be=20 done?
 
Many thanx in advance,
 
Best,
Oliveiros
------=_NextPart_000_002E_01CA4CE0.DED5A890-- From aklaver@comcast.net Wed Oct 14 20:54:38 2009 Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 00422633A76 for ; Wed, 14 Oct 2009 17:54:38 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 50093-07 for ; Wed, 14 Oct 2009 20:54:23 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from QMTA05.emeryville.ca.mail.comcast.net (qmta05.emeryville.ca.mail.comcast.net [76.96.30.48]) by mail.postgresql.org (Postfix) with ESMTP id 1CF5E632CF5 for ; Wed, 14 Oct 2009 17:54:27 -0300 (ADT) Received: from OMTA17.emeryville.ca.mail.comcast.net ([76.96.30.73]) by QMTA05.emeryville.ca.mail.comcast.net with comcast id sjvU1c0011afHeLA5kuTAD; Wed, 14 Oct 2009 20:54:27 +0000 Received: from tucker.local ([24.17.164.54]) by OMTA17.emeryville.ca.mail.comcast.net with comcast id skuK1c0031Ak4z48dkuQ0k; Wed, 14 Oct 2009 20:54:27 +0000 From: Adrian Klaver To: pgsql-sql@postgresql.org Subject: Re: How to order varchar data by word Date: Wed, 14 Oct 2009 13:54:17 -0700 User-Agent: KMail/1.9.10 Cc: "Oliveiros C," References: <6caee9520910140240u13daba93ua20637642727776e@mail.gmail.com> <99F66F53142145DE8127EAF7423AF726@marktestcr.marktest.pt> In-Reply-To: <99F66F53142145DE8127EAF7423AF726@marktestcr.marktest.pt> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200910141354.17785.aklaver@comcast.net> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.516 tagged_above=-10 required=5 tests=AWL=0.083, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200910/60 X-Sequence-Number: 33259 On Wednesday 14 October 2009 7:13:22 am Oliveiros C, wrote: > Hello, list. > > I have a table with a varchar field that I would like to order by word, not > by ordinal, which seems to be the default on postgres. > > Does anyone have a clue on how this can be done? > > Many thanx in advance, > > Best, > Oliveiros Can you show the SQL you are using? -- Adrian Klaver aklaver@comcast.net From oliveiros.cristina@marktest.pt Mon Oct 19 17:08:09 2009 Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 4F239633955 for ; Mon, 19 Oct 2009 14:08:09 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 77367-02-3 for ; Mon, 19 Oct 2009 17:08:00 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from jupiter.marktest.pt (delta.marktest.pt [80.251.174.116]) by mail.postgresql.org (Postfix) with ESMTP id 4C93E6331E8 for ; Mon, 19 Oct 2009 14:07:59 -0300 (ADT) Received: from Proteu (proteu.marktest.pt [10.61.90.54]) by jupiter.marktest.pt with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id 4R8TK4PR; Mon, 19 Oct 2009 18:07:57 +0100 Message-ID: From: "Oliveiros C," To: "Adrian Klaver" , References: <6caee9520910140240u13daba93ua20637642727776e@mail.gmail.com> <99F66F53142145DE8127EAF7423AF726@marktestcr.marktest.pt> <200910141354.17785.aklaver@comcast.net> Subject: Re: How to order varchar data by word Date: Mon, 19 Oct 2009 18:07:57 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 1 X-MSMail-Priority: High X-Mailer: Microsoft Outlook Express 6.00.2900.5512 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.002 tagged_above=-10 required=5 tests=BAYES_50=0.001, STOX_REPLY_TYPE=0.001 X-Spam-Level: X-Archive-Number: 200910/70 X-Sequence-Number: 33269 Hello, Adrian. Thank you for your email. I am not using any SQL at this time, but I 'd like to understand what is exactly the criterion that the ORDER BY uses to order text. Giving you some background : I need to make an efficient join between data generated by my program and data output by postgres and of course, it is mandatory that both lists of records be ordered using the same criterion. I need to figure out what is exactly the criterion used by postgres so I can mimic it on my program. I thought it was ordinal, but it seems it isnt, as the @ symbol comes before the 0 (zero). According to ASCII numeric codes, it shouldn't If any one can explain me exactly how the order by clause works on varchars, I 'd really appreciate it. I've already examined documentation carefully, but couldn't find it. Maybe I looked on the wrong place... Best, Oliveiros ----- Original Message ----- From: "Adrian Klaver" To: Cc: "Oliveiros C," Sent: Wednesday, October 14, 2009 9:54 PM Subject: Re: [SQL] How to order varchar data by word > On Wednesday 14 October 2009 7:13:22 am Oliveiros C, wrote: >> Hello, list. >> >> I have a table with a varchar field that I would like to order by word, >> not >> by ordinal, which seems to be the default on postgres. >> >> Does anyone have a clue on how this can be done? >> >> Many thanx in advance, >> >> Best, >> Oliveiros > > Can you show the SQL you are using? > > -- > Adrian Klaver > aklaver@comcast.net > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql From tgl@sss.pgh.pa.us Mon Oct 19 17:33:03 2009 Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id AC8EF632210 for ; Mon, 19 Oct 2009 14:33:03 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 80702-01 for ; Mon, 19 Oct 2009 17:32:56 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 1829E62F1B2 for ; Mon, 19 Oct 2009 14:32:55 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id n9JHWoH6008018; Mon, 19 Oct 2009 13:32:50 -0400 (EDT) To: "Oliveiros C," cc: "Adrian Klaver" , pgsql-sql@postgresql.org Subject: Re: How to order varchar data by word In-reply-to: References: <6caee9520910140240u13daba93ua20637642727776e@mail.gmail.com> <99F66F53142145DE8127EAF7423AF726@marktestcr.marktest.pt> <200910141354.17785.aklaver@comcast.net> Comments: In-reply-to "Oliveiros C," message dated "Mon, 19 Oct 2009 18:07:57 +0100" Date: Mon, 19 Oct 2009 13:32:49 -0400 Message-ID: <8017.1255973569@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.11 tagged_above=-10 required=5 tests=BAYES_05=-1.11 X-Spam-Level: X-Archive-Number: 200910/71 X-Sequence-Number: 33270 "Oliveiros C," writes: > If any one can explain me exactly how the order by clause works on varchars, > I 'd really appreciate it. It sorts according to the sort order imposed by your locale setting (see LC_COLLATE in particular). A lot of locales have weird and wonderful rules that embody somebody's notion of "dictionary order". If you don't like it, try switching to C locale. Or you could learn enough about locale definitions to create your own. regards, tom lane From oliveiros.cristina@marktest.pt Tue Oct 20 13:39:42 2009 Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 7D33E63281A for ; Tue, 20 Oct 2009 10:39:42 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 64553-02 for ; Tue, 20 Oct 2009 13:39:23 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from jupiter.marktest.pt (delta.marktest.pt [80.251.174.116]) by mail.postgresql.org (Postfix) with ESMTP id 8B9866327C5 for ; Tue, 20 Oct 2009 10:39:31 -0300 (ADT) Received: from Proteu (proteu.marktest.pt [10.61.90.54]) by jupiter.marktest.pt with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id 4R8TK9TJ; Tue, 20 Oct 2009 14:39:24 +0100 Message-ID: <754C7C57E773410197FA4BF910DE9973@marktestcr.marktest.pt> From: "Oliveiros C," To: "Tom Lane" Cc: "Adrian Klaver" , References: <6caee9520910140240u13daba93ua20637642727776e@mail.gmail.com> <99F66F53142145DE8127EAF7423AF726@marktestcr.marktest.pt> <200910141354.17785.aklaver@comcast.net> <8017.1255973569@sss.pgh.pa.us> Subject: Re: How to order varchar data by word Date: Tue, 20 Oct 2009 14:39:23 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5512 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.101 tagged_above=-10 required=5 tests=AWL=0.083, BAYES_40=-0.185, STOX_REPLY_TYPE=0.001 X-Spam-Level: X-Archive-Number: 200910/75 X-Sequence-Number: 33274 Hello, Tom. Thank you for your e-mail Even though I am not familiar with the exact procedure to switch to other locales, I'm gonna research this more deeply. Anyway, I would appreciate if you could spare me some time and give me a couple of pointers to this subject. Again, thank you Best, Oliveiros ----- Original Message ----- From: "Tom Lane" To: "Oliveiros C," Cc: "Adrian Klaver" ; Sent: Monday, October 19, 2009 6:32 PM Subject: Re: [SQL] How to order varchar data by word > "Oliveiros C," writes: >> If any one can explain me exactly how the order by clause works on >> varchars, >> I 'd really appreciate it. > > It sorts according to the sort order imposed by your locale setting > (see LC_COLLATE in particular). > > A lot of locales have weird and wonderful rules that embody somebody's > notion of "dictionary order". If you don't like it, try switching to > C locale. Or you could learn enough about locale definitions to create > your own. > > regards, tom lane > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql From aklaver@comcast.net Tue Oct 20 13:46:59 2009 Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id D9842632D4C for ; Tue, 20 Oct 2009 10:46:59 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 65649-07 for ; Tue, 20 Oct 2009 13:46:40 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from QMTA06.emeryville.ca.mail.comcast.net (qmta06.emeryville.ca.mail.comcast.net [76.96.30.56]) by mail.postgresql.org (Postfix) with ESMTP id DF82E63281A for ; Tue, 20 Oct 2009 10:46:48 -0300 (ADT) Received: from OMTA16.emeryville.ca.mail.comcast.net ([76.96.30.72]) by QMTA06.emeryville.ca.mail.comcast.net with comcast id v0Tz1c0051ZMdJ4A61mocR; Tue, 20 Oct 2009 13:46:48 +0000 Received: from tucker.local ([24.17.164.54]) by OMTA16.emeryville.ca.mail.comcast.net with comcast id v1us1c0031Ak4z48c1uslK; Tue, 20 Oct 2009 13:54:53 +0000 From: Adrian Klaver To: "Oliveiros C," Subject: Re: How to order varchar data by word Date: Tue, 20 Oct 2009 06:46:45 -0700 User-Agent: KMail/1.9.10 Cc: "Tom Lane" , pgsql-sql@postgresql.org References: <6caee9520910140240u13daba93ua20637642727776e@mail.gmail.com> <8017.1255973569@sss.pgh.pa.us> <754C7C57E773410197FA4BF910DE9973@marktestcr.marktest.pt> In-Reply-To: <754C7C57E773410197FA4BF910DE9973@marktestcr.marktest.pt> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200910200646.46157.aklaver@comcast.net> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.37 tagged_above=-10 required=5 tests=AWL=0.229, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200910/76 X-Sequence-Number: 33275 On Tuesday 20 October 2009 6:39:23 am Oliveiros C, wrote: > Hello, Tom. > > Thank you for your e-mail > > Even though I am not familiar with the exact procedure to switch to other > locales, > I'm gonna research this more deeply. > > Anyway, I would appreciate if you could spare me some time and give me a > couple of pointers to this subject. > > Again, thank you > > Best, > Oliveiros > A good place to start is: http://www.postgresql.org/docs/8.4/interactive/locale.html Check out the Further Reading section at: http://www.postgresql.org/docs/8.4/interactive/multibyte.html#AEN30078 -- Adrian Klaver aklaver@comcast.net From oliveiros.cristina@marktest.pt Tue Oct 20 15:54:58 2009 Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 1AFD76334DE for ; Tue, 20 Oct 2009 12:54:58 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 65041-03-2 for ; Tue, 20 Oct 2009 15:54:50 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from jupiter.marktest.pt (delta.marktest.pt [80.251.174.116]) by mail.postgresql.org (Postfix) with ESMTP id 007C76331B5 for ; Tue, 20 Oct 2009 12:54:49 -0300 (ADT) Received: from Proteu (proteu.marktest.pt [10.61.90.54]) by jupiter.marktest.pt with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id 4R8TLBB2; Tue, 20 Oct 2009 16:54:48 +0100 Message-ID: From: "Oliveiros C," To: "Adrian Klaver" Cc: "Tom Lane" , References: <6caee9520910140240u13daba93ua20637642727776e@mail.gmail.com> <8017.1255973569@sss.pgh.pa.us> <754C7C57E773410197FA4BF910DE9973@marktestcr.marktest.pt> <200910200646.46157.aklaver@comcast.net> Subject: Re: How to order varchar data by word Date: Tue, 20 Oct 2009 16:54:47 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5512 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.184 tagged_above=-10 required=5 tests=BAYES_40=-0.185, STOX_REPLY_TYPE=0.001 X-Spam-Level: X-Archive-Number: 200910/77 X-Sequence-Number: 33276 Hello, Adrian, thanks for the links. I enjoyed the technique on the end of the second page (on the version 8.3 with comments), the shadow column trick. Given that LC_COLLATE is immutable, unless a new database is created, I guess I'll give the shadow column a try. Best, Oliveiros ----- Original Message ----- From: "Adrian Klaver" To: "Oliveiros C," Cc: "Tom Lane" ; Sent: Tuesday, October 20, 2009 2:46 PM Subject: Re: [SQL] How to order varchar data by word > On Tuesday 20 October 2009 6:39:23 am Oliveiros C, wrote: >> Hello, Tom. >> >> Thank you for your e-mail >> >> Even though I am not familiar with the exact procedure to switch to other >> locales, >> I'm gonna research this more deeply. >> >> Anyway, I would appreciate if you could spare me some time and give me a >> couple of pointers to this subject. >> >> Again, thank you >> >> Best, >> Oliveiros >> > > A good place to start is: > http://www.postgresql.org/docs/8.4/interactive/locale.html > Check out the Further Reading section at: > http://www.postgresql.org/docs/8.4/interactive/multibyte.html#AEN30078 > > -- > Adrian Klaver > aklaver@comcast.net