【问题标题】:postgresql include accentuated letters in alphabetical order in search resultspostgresql 在搜索结果中按字母顺序包含重音字母
【发布时间】:2017-02-15 20:44:51
【问题描述】:

我在我的 postgresql 数据库中安装了 unaccent(尽管不确定这是否与我的问题相关)。

当我做一个简单的时候

select * from keywords order by keyword desc;

返回以œ然后éè等开头的所有条目。我希望这些条目位于以普通e开头的单词内,这样命令应该返回以@987654326开头的单词的最高排名@,比y 等等。

我试过了:

select unaccent(*) from keywords order by keyword desc;

这不好,因为 unaccent 只是全文搜索并且不强调搜索词,而不是结果。

【问题讨论】:

  • 我不知道它是否是您查询中的拼写错误(以及它是否有效),但select unaccent(*) 很奇怪。也许你只有 1 列?无论哪种方式,您都应该将unaccent 放入ORDER BY 子句中,例如select * from keywords order by unaccent(keyword) desc

标签: postgresql


【解决方案1】:

这是一个整理问题。检查您正在使用的那个或只使用您想要的那个:

with t (w) as ( values ('œ'),('é'),('è'),('z'),('y'))
select w
from t
order by w collate "pt_BR" desc;
 w 
---
 z
 y
 œ
 è
 é

在这种情况下,pt_BR 按预期工作。

https://www.postgresql.org/docs/current/static/collation.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-20
    • 2013-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-08
    • 2014-01-21
    • 1970-01-01
    相关资源
    最近更新 更多