本文介绍了字符串排序顺序(LC_COLLATE和LC_CTYPE)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然,自8.4版本
以来,PostgreSQL允许每个数据库使用不同的语言环境。因此,我去了文档以了解语言环境(http://www.postgresql.org/docs/8.4/static/locale.html)。

Apparently PostgreSQL allows different locales for each database since version 8.4So I went to the docs to read about locales (http://www.postgresql.org/docs/8.4/static/locale.html).

我特别感兴趣的是字符串排序顺序(我希望将字符串排序为 A abc D d而不是 ABC ... Z ab c)。

String sort order is of my particular interest (I want strings sorted like 'A a b c D d' and not 'A B C ... Z a b c').

问题1:创建数据库时,我是否仅需要设置LC_COLLATE(字符串排序顺序)?

Question 1: Do I only need to set LC_COLLATE (String sort order) when I create a database?

I还阅读了有关LC_CTYPE(字符分类(什么是字母?大写字母?)的信息。)

I also read about LC_CTYPE (Character classification (What is a letter? Its upper-case equivalent?))

问题2:有人可以解释一下这是什么意思吗?

Question 2: Can someone explain what this means?

推荐答案

您描述的排序顺序是大多数语言环境中的标准。
自己尝试一下:

The sort order you describe is the standard in most locales.Just try for yourself:

SELECT regexp_split_to_table('D d a A c b', ' ') ORDER BY 1;

使用中,您可以使用-locale = some_locale 选择语言环境。就我而言,它是-locale = de_AT.UTF-8 。如果您未指定任何语言环境,则将从您的系统语言环境中继承。

When you initialize your db cluster with initdb you can can pick a locale with --locale=some_locale. In my case it's --locale=de_AT.UTF-8. If you don't specify anything the locale is inherited from the environment - your current system locale will be used.

集群的模板数据库将设置为该语言环境。创建新数据库时,它将从模板继承设置。通常,您不必担心任何事情,它们都可以正常工作。

The template database of the cluster will be set to that locale. When you create a new database, it inherits the settings from the template. Normally you don't have to worry about anything, it all just works.

阅读以获取更多信息。
如果您想通过索引加速文本搜索,请务必阅读。

Read the chapter on CREATE DATABASE for more.If you want to speed up text search with indexes, be sure to read about operator classes, as well.

PostgreSQL 9.1 或更高版本中,有允许更灵活地使用归类:

In PostgreSQL 9.1 or later, there is collation support that allows more flexible use of collations:

这篇关于字符串排序顺序(LC_COLLATE和LC_CTYPE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 02:48