Re: numerical sort on mixed alpha/numeric data

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: numerical sort on mixed alpha/numeric data
Date: 2003-07-16 16:41:06
Message-ID: 20030716164106.GC1263@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, Jul 16, 2003 at 12:48:26 +0100,
Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk> wrote:
> Hi folks,
>
> I've got a table holding loco numbers and an id which references the locos
> table. How can I sort this table, so that numeric values appear first in
> numerical order followed by alpha in alpha order.?

You can first sort by whether or not a pattern match succeeds. You haven't
said whether or not the empty string is a number or an alpha and that will
affect the choice of pattern.

For example:
select * from lumbers order by lumber !~ '^[0-9]+$', lumber;

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message floyds 2003-07-16 16:54:41 Re: column doesn't get calculated - update # 2
Previous Message Andreas 2003-07-16 15:44:16 "Truncate [ Table ] name [Cascade]"?