Postgresql sorting mixed alphanumeric data

前端 未结 7 1513
无人及你
无人及你 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:12

    You can simply cast name column to bytea data type allowing collate-agnostic ordering:

    SELECT name
    FROM folders
    ORDER BY name::bytea;
    

    Result:

         name     
    --------------
     a test
     alphanumeric
     test 1
     test 10
     test 19
     test 20
    (6 rows)
    

提交回复
热议问题