Postgresql sorting mixed alphanumeric data

前端 未结 7 1458
无人及你
无人及你 2020-12-30 05:32

Running this query:

select name from folders order by name

returns these results:

alphanumeric
a test
test 20
test 19
test          


        
7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-30 06:20

    All of this methods sorted my selection in alphabetical order:

    test 1
    test 10
    test 2
    test 20
    

    This solution worked for me (lc_collate: 'ru_RU.UTF8'):

    SELECT name
    FROM folders
    ORDER BY SUBSTRING(name FROM '([0-9]+)')::BIGINT ASC, name;
    
    test 1
    test 2
    test 10
    test 20
    

提交回复
热议问题