Re: ORDER BY handling mixed integer and varchar values

Поиск
Список
Период
Сортировка
От Rod Taylor
Тема Re: ORDER BY handling mixed integer and varchar values
Дата
Msg-id 1116271164.696.80.camel@home
обсуждение исходный текст
Ответ на 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??

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 по дате отправления:

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