Re: ORDER BY handling mixed integer and varchar values

From: Rod Taylor <pg(at)rbt(dot)ca>
To: David B <davidb999(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: ORDER BY handling mixed integer and varchar values
Date: 2005-05-16 19:19:24
Message-ID: 1116271164.696.80.camel@home
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> 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.
--

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Ragnar Hafstað 2005-05-16 19:32:40 Re: ORDER BY handling mixed integer and varchar values
Previous Message Edmund Bacon 2005-05-16 19:18:22 Re: ORDER BY handling mixed integer and varchar values