Re: natural sort order

From: Ken Guest <ken(at)tuatha(dot)org>
To: Arguile <arguile(at)lucentstudios(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: natural sort order
Date: 2003-02-17 09:12:45
Message-ID: 3E50A78D.4060702@tuatha.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Arguile wrote:

>On Fri, 2003-02-14 at 10:14, Ken Guest wrote:
>
>
>>Is it possible to use a natural sort order?
>>I want to get data back in the order
>>CD1, CD2, CD3., CD4, CD5, CD6, CD7, CD8, CD9, CD10, CD11
>>
>>
>
>You have a couple options. The bandaid solutions is:
>
> SELECT * FROM table ORDER BY substr(field, 3)::int
>
>It might also be a good idea to look at why CD is prefixed to each. If
>they're all CDs maybe just drop the prefix? You can always concat it on
>the front for reports.
>
>

That works well, though I had to add in a where clause because not all
entries are prefixed by 'CD',
so it's more of
select id from pricing where id like 'CD%' order by substr(id, 3)::int;

Thanks Arguile,

k.

________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service. For more information on a proactive anti-virus service working
around the clock, around the globe, visit http://www.messagelabs.com
________________________________________________________________________

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Deepa 2003-02-17 09:13:40 Re: Creating index does not make any change in query plan.
Previous Message Shridhar Daithankar 2003-02-17 09:11:22 Re: Creating index does not make any change in query plan.