Ordering differences between Postgres instances on different machines (same locale)

自闭症网瘾萝莉.ら 提交于 2019-12-22 09:04:10

问题


I have two Postgres 9.1 instances: one local, installed via Postgres.app on OS X, and one remote, on Heroku. I've ensured that lc_collate is en_US.UTF-8 on both machines but am still seeing different behavior between the two.

On my local instance, SELECT 'i' > 'N' returns t whereas remotely it returns f. Given that I've already checked lc_* on both systems, what explains the difference I'm seeing?


回答1:


From the point of view of Unicode, the case ordering is a customization. Excerpt from http://www.unicode.org/reports/tr10:

Case Ordering. Some dictionaries and authors collate uppercase before lowercase while others use the reverse, so that preference needs to be customizable. Sometimes the case ordering is mandated by the government, as in Denmark. Often it is simply a customization or user preference.

Mac OS X simply has a different case ordering than the OS used by Heroku. On Mac OS X:

$ LC_CTYPE=en_US.UTF-8 sort << EOF
> i
> N
> EOF

produces:

N
i

The exact same command and same data on Ubuntu 12.04 produces:

i
N

This has none to do with PostgreSQL, except for the fact that it uses the OS for collation, so these unfortunate discrepancies between different OS impact databases.

PostgreSQL 10 and ICU

Starting with version 10, PostgreSQL may use collations provided by the ICU library, for servers compiled with ICU. These collations can sort consistently across operating systems.



来源:https://stackoverflow.com/questions/13370051/ordering-differences-between-postgres-instances-on-different-machines-same-loca

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!