PostgreSQL Sort

后端 未结 4 658
执笔经年
执笔经年 2020-12-07 03:45

I have a sort problem in PostgreSQL with below data:

name
-----
@CF
@CG
CD
CE

I used select name from table order by name, the

4条回答
  •  执念已碎
    2020-12-07 04:26

    Your undisclosed collation setting obviously ignores the @ character for sort order. Either switch to another collation as suggested by @Craig. Or, if you want to stick to your collation for the rest of the string, add a special case for leading @.

    In Postgres you can order by boolean values directly. Default order is FALSE, TRUE, NULL.

    ORDER BY name !~~ '@%', name
    

    !~~ being the Postgres shorthand for NOT LIKE.

提交回复
热议问题