Re: please need help: alpha numeric sorting

From: "Markus Wollny" <Markus(dot)Wollny(at)computec(dot)de>
To: "Raouf" <aimeur(at)prodigy(dot)net>, "Duncan Adams (DNS)" <duncan(dot)adams(at)vcontractor(dot)co(dot)za>, <pgsql-novice(at)postgresql(dot)org>
Subject: Re: please need help: alpha numeric sorting
Date: 2002-08-02 09:26:51
Message-ID: 2266D0630E43BB4290742247C891057501B131F5@dozer.computec.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I don't know of anything - but I'm quite knew to pgsql, too. You might
try to do this in your application by parsing the numbers between the
dots and the doing a sort.

-----Ursprüngliche Nachricht-----
Von: Raouf [mailto:aimeur(at)prodigy(dot)net]
Gesendet: Freitag, 2. August 2002 11:26
An: Duncan Adams (DNS); pgsql-novice(at)postgresql(dot)org
Betreff: Re: [NOVICE] please need help: alpha numeric sorting

Hello Markus,

thanks for your reply. Yes I was thinking of splitting my fields in to 2
separate fields but actually I need to have the dot between the numbers,
e.g 12.1 or 12.1.2, so actually it won't change anything for me. Do you
know if thers's a function that I could use for the sorting ?

thanks,

----- Original Message -----
From: Duncan Adams (DNS) <mailto:duncan(dot)adams(at)vcontractor(dot)co(dot)za>
To: pgsql-novice(at)postgresql(dot)org
Sent: Friday, August 02, 2002 2:00 AM
Subject: Re: [NOVICE] please need help: alpha numeric sorting

is there no way around splitting the field.
i have the same problem, i have ports that i would like to order by
numeric. my main problem been that some ports are called a1 - a24 and
then b1 - b24 and other devices have ports 1a - 24a, 1b - 24b ect.

-----Original Message-----
From: Markus Wollny [ mailto:Markus(dot)Wollny(at)computec(dot)de]
Sent: Friday, August 02, 2002 10:56 AM
To: Raouf; pgsql-novice(at)postgresql(dot)org
Subject: Re: [NOVICE] please need help: alpha numeric sorting

Hello!

The resulting sorting order is quite correct in terms of alphanumeric
sorting. If you want numeric sorting, you would probably need to
separate the leading number from the tailing string, so you had two
fields e.g. "chapter_nr" of type float4 and "chapter_title" of type text
(if that's what it is). Then you could just order by chapter_nr and
would get a numerically correct sort instead of the alphanumerically
correct sort. Alphanumeric always goes character per character from left
to right and therefore n.11 is coming before n.2 - the tailing 1 after
the first 1 doesn't matter, because n.11 is not regarded as n, point and
eleven but n, point and two ones in sequence.

Regards,

Markus

-----Ursprüngliche Nachricht-----
Von: Raouf [mailto:aimeur(at)prodigy(dot)net]
Gesendet: Freitag, 2. August 2002 10:49
An: pgsql-novice(at)postgresql(dot)org
Betreff: [NOVICE] please need help: alpha numeric sorting

Hi Gurus,

I need your help for this one:

let's say I have 1 field of type VARCHAR that contains numbers (as
ascii) and characters like this:


title
-----------
12.1 cisco ccnp routing
12.2 cisco ccnp remote access
12.11cisco ccnp switching
12.3 cisco ccnp support


I'd like to sort that column in alphanumeric order, like this:

title
-----------
12.1 cisco ccnp routing
12.2 cisco ccnp remote access
12.3 cisco ccnp support
12.11cisco ccnp switching


but if I sort using group by title and order by title asc I have:


title
-----------
12.1 cisco ccnp routing
12.11cisco ccnp switching
12.2 cisco ccnp remote access
12.3 cisco ccnp support
12.11cisco ccnp switching

where "12.11cisco ccnp switching" is before "12.2 cisco ccnp remote
access" because it is smaller.

Is it possible ?

thanks for your help

Browse pgsql-novice by date

  From Date Subject
Next Message Ludwig Lim 2002-08-02 09:31:13 Re: please need help: alpha numeric sorting
Previous Message Raouf 2002-08-02 09:25:32 Re: please need help: alpha numeric sorting