Re: Sorting by numerical order
От | George Essig |
---|---|
Тема | Re: Sorting by numerical order |
Дата | |
Msg-id | 20040315201212.93490.qmail@web80206.mail.yahoo.com обсуждение исходный текст |
Ответ на | Sorting by numerical order (CSN <cool_screen_name90001@yahoo.com>) |
Список | pgsql-general |
Steve Atkins wrote: > > Couldn't you just use a regex match? foo ~ '-?[0-9]+(\.[0-9]+)?' or > somesuch. > > Cheers, > Steve This helps a lot. I used a similar regular expression, the substring function, and the order by clause to do the following: test=# select * from sort_test order by name; name -------- 10 aaa abc abc 1 abc 10 abc 2 abc 20 (7 rows) test=# select name, substring(name from '^(.*?)([-+]?[0-9]+(\\.[0-9]+)?)?$') as start_string, substring(name from '[-+]?[0-9]+(\\.[0-9]+)?$')::float as end_number from sort_test order by start_string, end_number; name | start_string | end_number --------+--------------+------------ 10 | | 10 aaa | aaa | abc | abc | abc 1 | abc | 1 abc 2 | abc | 2 abc 10 | abc | 10 abc 20 | abc | 20 (7 rows) George Essig
В списке pgsql-general по дате отправления: