PostgreSQL排序 [英] PostgreSQL Sort
本文介绍了PostgreSQL排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在PostgreSQL中有以下数据的排序问题:
I have a sort problem in PostgreSQL with below data:
name
-----
@CF
@CG
CD
CE
I使用从表顺序中按名称选择名称
,结果如下:
name
-----
CD
CE
@CF
@CE
似乎Postgres只是忽略特殊字符 @
并对左字符串进行排序。但是,我希望将其排序为:
It seems that Postgres just ignores the special character @
and sorts the left string. However, I'd like it sorted like this:
name
-----
@CF
@CG
CD
CE
搜索互联网没有没有帮助。我希望这里有人可以提出建议。
Searching the internet didn't help. I hope someone here could give a suggestion.
推荐答案
使用 PostgreSQL的排序规则支持告诉它您想要特定的排序规则。
Use PostgreSQL's collation support to tell it you want a particular collation.
给出: / p>
Given:
CREATE TABLE t AS VALUES ('CD'),('CE'),('@CF'),('@CE');
您可以使用以下方式强制按字节排序:
You can force byte-wise collation using:
SELECT * FROM t ORDER BY column1 COLLATE "C";
C
排序规则是一个字节明智的排序规则,忽略了国家语言规则,编码等。
The "C"
collation is a byte-wise collation that ignores national language rules, encoding, etc.
这篇关于PostgreSQL排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文