Re: ORDER BY handling mixed integer and varchar values - Mailing list pgsql-sql

From Rod Taylor
Subject Re: ORDER BY handling mixed integer and varchar values
Date
Msg-id 1116271164.696.80.camel@home
Whole thread Raw
In response to ORDER BY handling mixed integer and varchar values  (David B <davidb999@gmail.com>)
List 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.
-- 



pgsql-sql by date:

Previous
From: Edmund Bacon
Date:
Subject: Re: ORDER BY handling mixed integer and varchar values
Next
From: Ragnar Hafstað
Date:
Subject: Re: ORDER BY handling mixed integer and varchar values