From: Rod Taylor <pg@rbt.ca>
To: David B <davidb999@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: ORDER BY handling mixed integer and varchar values
Date: Mon, 16 May 2005 15:19:24 -0400
Message-ID: <1116271164.696.80.camel@home> (raw)
In-Reply-To: <c76ea21c050516114742818cfa@mail.gmail.com>
References: <c76ea21c050516114742818cfa@mail.gmail.com>
> Is there any elegent query you folks can think of that combines the
> two so I can one query that has alpha sorting on alpha categories and
> numeric sorting on numeric values that are in the same column??
select * from r order by (case when col ~ '^[0-9]+$' THEN lpad(col, 10,
'0') else col end) ;
Left pad the numbers with 0's, but don't touch the text strings. Sort
based on that.
--
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: pg@rbt.ca, davidb999@gmail.com
Subject: Re: ORDER BY handling mixed integer and varchar values
In-Reply-To: <1116271164.696.80.camel@home>
* 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