我在 Postgres 中对挪威文本列进行排序时遇到问题。
我的环境:
db=# select version();
PostgreSQL 9.2.14 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4), 64-bit
数据库托管在 RedHat Openshift 上。
运行时
>locale
我得到的命令:**编辑
db=#\l
Name | Owner | Encoding | Collate | Ctype | Access privileges
-------------------------+--------------+----------+-------------+-------------+-----------------------
db | myadminUser | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
这是我试过的
此 sql 显示默认排序不正确:
db=# select * from unnest(ARRAY['a','b','c','d','A','B','C','å','ø','z','Z','Ø']) as t1 order by t1;
结果:一种
一种
一种
乙
乙
C
C
d
ø
Ø
z
Z
(我认为这种排序顺序对于英语来说甚至是错误的,大写的 'A' 应该在 'a' 之前,不是吗?)
然后我试过:
db=# CREATE COLLATION nor (LOCALE = 'nn_NO.utf8');
以及之前的相同声明:
db=# select * from unnest(ARRAY['a','b','c','d','A','B','C','å','ø','z','Z','Ø']) as t1 order by t1 collate nor;
现在的结果是:一种
一种
乙
乙
C
C
d
Z
z
Ø
ø
å
这看起来非常好,我以为我已经完成了..但后来我尝试了:
db=# select * from unnest(ARRAY['aaaa','bbbb','cccc','dddd','AAAA','BBBB','CCCC','åååå','øøøø','zzzz','ZZZZ','ØØØØ']) as t1 order by t1 collate nor;
结果: BBBB
bbbb
中交所
cccc
滴滴
ZZZZ
呜呜呜
ØØØØ
øøøø
美国AAAA
啊啊啊
åååå
我在这里做错了什么?
最佳答案
顺序是正确的。在挪威语中,“aa”是“å”的拼写,它应该放在最后。
来源:https://en.wikipedia.org/wiki/%C3%85
Correct alphabetization in Danish and Norwegian places Å as the last letter in the alphabet, the sequence being Æ, Ø, Å. This is also true for the alternative spelling "Aa". Unless manually corrected, sorting algorithms of programs localised for Danish or Norwegian will place e.g., Aaron after Zorro.
关于postgresql - 如何在 Postgres 上对挪威文本进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34154030/