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

From PFC
Subject Re: ORDER BY handling mixed integer and varchar values
Date
Msg-id op.sqvua2ogth1vuj@localhost
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??

solution 1 (fast)

make a separate column which contains the integer value (updated via a  
trigger) or NULL if it's a textual value, then sort on it

solution 2

order by the string padded to a fixed length by adding spaces to the left :
(here an underscore is a space):

____1
___10
_ABCD

I think there's a LPAD function (look in the docs) to do that... you can  
use only the first N (like 10) chars of the string...



pgsql-sql by date:

Previous
From: David B
Date:
Subject: ORDER BY handling mixed integer and varchar values
Next
From: Edmund Bacon
Date:
Subject: Re: ORDER BY handling mixed integer and varchar values