且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在带有Postgresql 9.6的Django中,如何区分大小写和不区分重音?

更新时间:2022-12-18 15:12:00

它与Django本身无关,PostgreSQL的 lc_collat​​e 配置确定这一点。我建议您检查其值:

It isn't related to Django itself, PostgreSQL's lc_collate configuration determines this. I'd suggest you to review its value:

SHOW lc_collate;

正确的做法是修复此配置。别忘了看一下相关的设置( lc_ctype 等)。

The right thing to do is fix this configuration. Don't forget to take a look on related settings too (lc_ctype, etc.).

但是如果您无法使用正确的设置创建另一个数据库,请尝试在 ORDER 上显式地显示 collat​​e ,如下例所示:

But if you cannot create another database with the right setting, try to explicit collate on ORDER like the following test case:

CREATE TEMPORARY TABLE table1 (column1 TEXT); 

INSERT INTO table1 VALUES('Barn'),
('beef'),
('bémol'),
('Bœuf'),
('boulette'),
('Bubble');

SELECT * FROM table1 ORDER BY column1 COLLATE "en_US"; --Gives the expected order
SELECT * FROM table1 ORDER BY column1 COLLATE "C"; --Gives "wrong" order  (in your case)

请务必记住PostgreSQL依赖于操作系统区域设置。此测试用例已在CentOS 7上执行。更多信息此处和此处。

It's important to remember that PostgreSQL relies on operating system locales. This test case was executed on CentOS 7. More info here and here.