Alphanumeric case in-sensitive sorting in postgres

前端 未结 6 1166
青春惊慌失措
青春惊慌失措 2020-12-17 09:33

I am new to postrges and want to sort varchar type columns. want to explain the problem with with below example:

table name: testsorting

   order             


        
6条回答
  •  南笙
    南笙 (楼主)
    2020-12-17 10:15

    If the name is always in the 1 alpha followed by n numerics format then:

    select name
    from testsorting
    order by
        upper(left(name, 1)),
        (substring(name from 2) || '0')::integer
    

提交回复
热议问题