From: Bruno Wolff III <bruno@wolff.to>
To: Gary Stainburn <gary.stainburn@ringways.co.uk>
Cc: pgsql-sql@postgresql.org
Subject: Re: numerical sort on mixed alpha/numeric data
Date: Wed, 16 Jul 2003 11:41:06 -0500
Message-ID: <20030716164106.GC1263@wolff.to> (raw)
In-Reply-To: <200307161248.26835.gary.stainburn@ringways.co.uk>
References: <200307161248.26835.gary.stainburn@ringways.co.uk>
On Wed, Jul 16, 2003 at 12:48:26 +0100,
Gary Stainburn <gary.stainburn@ringways.co.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;
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: bruno@wolff.to, gary.stainburn@ringways.co.uk
Subject: Re: numerical sort on mixed alpha/numeric data
In-Reply-To: <20030716164106.GC1263@wolff.to>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox