"order by" 子句中的不同行为:Oracle 与 PostgreSQL
Different behaviour in "order by" clause: Oracle vs. PostgreSQL
我有以下 table(在 Oracle 和 PostgreSQL 中创建并填充它们):
> create table foo (a varchar(10));
我用值填充了它们,order by
子句在 PostgreSQL 和 Oracle 中的行为不同(我认为版本与这个问题无关):
甲骨文:
> select a, length(a) from foo order by a;
A LENGTH(A)
---------- ----------
.1 2
01 2
1 1
1#0 3
1#1 3
1.0 3
1.1 3
10 2
11 2
9 rows selected.
我得到了我所期望的。 .1
在 01
之前,因为 .
在 ascii table.
之前 0
然而,在 PostgreSQL 中我有:
=> select a, length(a) from foo order by a;
a | length
-----+--------
01 | 2
1 | 1
.1 | 2
10 | 2
1.0 | 3
1#0 | 3
11 | 2
1.1 | 3
1#1 | 3
(9 rows)
为什么不同?我知道它可能与整理顺序或类似的东西有关,但我想要一些关于在哪里可以阅读更多相关信息的指示。
更新:整理有关 PostgreSQL 数据库的信息:
Encoding: UTF8
Collante: en_US.UTF-8
Ctype: en_US.UTF-8 |
谢谢!
Postgres 只有两个内置排序规则:C 和 POSIX。
任何其他归类由操作系统提供。
在许多采用 UTF 语言环境的 linux 系统上,所有非字母数字字符在排序期间都会被忽略。
您可以使用collate C
获得预期结果:
select a, length(a) from foo order by a collate "C";
你可以找到更详细的解释in this answer。
我有以下 table(在 Oracle 和 PostgreSQL 中创建并填充它们):
> create table foo (a varchar(10));
我用值填充了它们,order by
子句在 PostgreSQL 和 Oracle 中的行为不同(我认为版本与这个问题无关):
甲骨文:
> select a, length(a) from foo order by a;
A LENGTH(A)
---------- ----------
.1 2
01 2
1 1
1#0 3
1#1 3
1.0 3
1.1 3
10 2
11 2
9 rows selected.
我得到了我所期望的。 .1
在 01
之前,因为 .
在 ascii table.
0
然而,在 PostgreSQL 中我有:
=> select a, length(a) from foo order by a;
a | length
-----+--------
01 | 2
1 | 1
.1 | 2
10 | 2
1.0 | 3
1#0 | 3
11 | 2
1.1 | 3
1#1 | 3
(9 rows)
为什么不同?我知道它可能与整理顺序或类似的东西有关,但我想要一些关于在哪里可以阅读更多相关信息的指示。
更新:整理有关 PostgreSQL 数据库的信息:
Encoding: UTF8
Collante: en_US.UTF-8
Ctype: en_US.UTF-8 |
谢谢!
Postgres 只有两个内置排序规则:C 和 POSIX。 任何其他归类由操作系统提供。 在许多采用 UTF 语言环境的 linux 系统上,所有非字母数字字符在排序期间都会被忽略。
您可以使用collate C
获得预期结果:
select a, length(a) from foo order by a collate "C";
你可以找到更详细的解释in this answer。