【发布时间】:2012-12-03 10:20:55
【问题描述】:
查询
select 'T' union all select 'Z' order by 1
返回
Z
T
但正确的顺序应该是
T
Z
在 3 种不同的操作系统中尝试过
- Windows 2003 服务器“PostgreSQL 9.1.3,由 Visual C++ build 1500 编译,32 位”
- Windows 7 "PostgreSQL 9.2.1,由 Visual C++ build 1600 编译,32 位"
- Debian“x86_64-unknown-linux-gnu 上的 PostgreSQL 9.1.2,由 gcc-4.4.real (Debian 4.4.5-8) 4.4.5, 64-bit 编译”
数据库设置为:
Collation: et_EE.UTF-8
Character type: et_EE.UTF-8
如何解决这个问题?
更新
数据库是使用
创建的CREATE DATABASE mydb WITH TEMPLATE=template0 OWNER=mydb_owner ENCODING='UNICODE'
操作系统语言环境在所有情况下都是爱沙尼亚语,因此数据库是在爱沙尼亚语语言环境中创建的。
select 'Z' collate "et_EE" union all select 'S' collate "et_EE" order by 1
返回正确的顺序:
S
Z
但是
select 'Z' collate "et_EE" union all select 'T' collate "et_EE" order by 1
如回答中所述返回无效订单:
Z
T
【问题讨论】:
-
除了此顺序根据爱沙尼亚排序规则有效 - Z 必须在 T 之前
-
还有:PostgreSQL 9.1.3?我引用项目页面:
We always recommend that all users run the latest available minor release for whatever major version is in use.那将是 9.1.7。
标签: sql postgresql sql-order-by locale collation