Re: ORDER BY handling mixed integer and varchar values

Поиск
Список
Период
Сортировка
От PFC
Тема Re: ORDER BY handling mixed integer and varchar values
Дата
Msg-id op.sqvua2ogth1vuj@localhost
обсуждение исходный текст
Ответ на ORDER BY handling mixed integer and varchar values  (David B <davidb999@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: David B
Дата:
Сообщение: ORDER BY handling mixed integer and varchar values
Следующее
От: Edmund Bacon
Дата:
Сообщение: Re: ORDER BY handling mixed integer and varchar values