简体   繁体   English

区分大小写的排序(词法排序)不起作用 PostgreSQL citext 类型

[英]Case sensitive sorting (lexical sorting) not working PostgreSQL citext type

I want to perform search and sorting simultaneously for the citext type in PostgreSQL.我想对 PostgreSQL 中的citext类型同时执行搜索和排序。

select name from employee ORDER BY name ASC;

For the above query I get the following sort order:对于上述查询,我​​得到以下排序顺序:

"Adam"
"balaji"
"Cartus"
"dalal"
"erfan"
"Eric"
"Focus"
"lucus"

Is there any way to sort in the below order:有没有办法按以下顺序排序:

"Adam"
"Cartus"
"Eric"
"Focus"
"balaji"
"dalal"
"erfan"
"lucus"

I am using postgres version "PostgreSQL 9.4.10, compiled by Visual C++ build 1800, 64-bit".我使用的是 postgres 版本“PostgreSQL 9.4.10,由 Visual C++ build 1800,64 位编译”。

You could use你可以用

ORDER BY name::text COLLATE "POSIX"

That will cast name to a case sensitive type and use the binary collation.这会将name转换为区分大小写的类型并使用二进制排序规则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM