'P 0'<'P!'在python和postgresql中

f p*_*f p 9 python postgresql

Python中的脚本不起作用,我将问题简化为以下内容.

在PostgreSQL 9.1中我尝试过:

SELECT 'P 0' < 'P! '
f
Run Code Online (Sandbox Code Playgroud)

在Python 2.7.3中:

>>> 'P 0' < 'P! '
True
Run Code Online (Sandbox Code Playgroud)

为什么' '不低于'!'PostgreSQL?怎么了?

Cra*_*ger 7

PostgreSQL使用您的语言环境的排序规则进行字符串比较.Python使用不同的语言环境(可能是"C")进行整理.

如果不知道你的数据库LC_COLLATE是什么(来自\l+in psql)以及Python的运行时环境是什么,很难说更多.尝试显示数据库区域设置和shell locale命令的输出.

请参阅locales上的PostgreSQL文档.

例如,比较和对比:

-- results may vary depending on your OS/libc
SELECT 'P 0' < 'P! ' COLLATE "C"; -- returns true
SELECT 'P 0' < 'P! ' COLLATE "en_GB"; -- returns false
Run Code Online (Sandbox Code Playgroud)