在Postgres中按波兰语对字符串排序

huangapple go评论93阅读模式
英文:

Order Strings with polish in Postgres

问题

以下是翻译的内容:

如何以包含波兰字母的某个字符串字段对实体进行排序?是否可以通过Spring Data实现?我是否可以将Locale包含到Pageable中以实现这一点?:

Page<Collection> findByInstitutionIdAndIsDeletedFalse(Long institutionId, Pageable pageable);

以及

Sort.Order entityOrder = Sort.Order.by("title").ignoreCase();
PageRequest pageable = PageRequest.of(page, perPage, Sort.by(entityOrder));

当我这样做时,得到的结果是:

  • alaska
  • lalka
  • termos
  • łóżko

但是“łóżko”应该在“lalka”之后。

我尝试过在Postgres数据库中更改Locale,但无论是对于db1还是db2都没有起作用。

   名称   | 所有者 | 编码  |    校对    |    ctype    |   访问权限   
-----------+--------+-------+------------+------------+-----------------------
 db1       | 用户   | UTF8  | pl_PL      | pl_PL      | 
 db2       | 用户   | UTF8  | pl_PL.utf8 | pl_PL.utf8 | 
 db3       | 用户   | UTF8  | en_US.utf8 | en_US.utf8 | 

感谢任何建议!

英文:

What is the best way to order Entities by some String field that contains polish letters?
Is there a way to do that with Spring Data? Can I include Locale into Pageabe for this?:

Page&lt;Collection&gt; findByInstitutionIdAndIsDeletedFalse(Long institutionId, Pageable pageable);

and

Sort.Order entityOrder = Sort.Order.by(&quot;title&quot;).ignoreCase();
PageRequest pageable = PageRequest.of(page, perPage, Sort.by(entityOrder));

When I do like that, I have:

  • alaska
  • lalka
  • termos
  • łóżko

But "łóżko" should be after "lalka".

I tried to change Locale in Postgres database, but it didn't work for db1 nor db2.

   Name    |  Owner   | Encoding |  Collate   |   Ctype    |   Access privileges   
-----------+----------+----------+------------+------------+-----------------------
 db1       | user     | UTF8     | pl_PL      | pl_PL      | 
 db2       | user     | UTF8     | pl_PL.utf8 | pl_PL.utf8 | 
 db3       | user     | UTF8     | en_US.utf8 | en_US.utf8 | 

Thanks for any suggestions!

答案1

得分: 0

好的,以下是您要翻译的内容:

我已将 postgres 版本从 alpine 更改为 9.6,并且在 Dockerfile 中添加了以下行:

RUN localedef -i pl_PL -c -f UTF-8 -A /usr/share/locale/locale.alias pl_PL.UTF-8
ENV LANG PL_PL.utf8
ENV LC_ALL="pl_PL.UTF-8"
ENV LC_CTYPE="pl_PL.UTF-8"

现在它正在工作,我也有了正确的顺序。但是我仍然在考虑如何从 docker-compose 文件构建我的 postgres。

英文:

Ok, I've changed postgres version from alpine to 9.6, and in Dockerfile I have these lines:

RUN localedef -i pl_PL -c -f UTF-8 -A /usr/share/locale/locale.alias pl_PL.UTF-8
ENV LANG PL_PL.utf8
ENV LC_ALL=&quot;pl_PL.UTF-8&quot;
ENV LC_CTYPE=&quot;pl_PL.UTF-8&quot;

Now It's working and I have right order. But still I'am wondering how to build my postgres from docker-compose file.

huangapple
  • 本文由 发表于 2020年7月28日 22:25:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/63136409.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定