Movatterモバイル変換


[0]ホーム

URL:



Facebook
Postgres Pro
Facebook
Downloads
CREATE COLLATION
Prev UpSQL CommandsHome Next

CREATE COLLATION

CREATE COLLATION — define a new collation

Synopsis

CREATE COLLATION [ IF NOT EXISTS ]name (    [ LOCALE =locale, ]    [ LC_COLLATE =lc_collate, ]    [ LC_CTYPE =lc_ctype, ]    [ PROVIDER =provider, ]    [ DETERMINISTIC =boolean, ]    [ RULES =rules, ]    [ VERSION =version ])CREATE COLLATION [ IF NOT EXISTS ]name FROMexisting_collation

Description

CREATE COLLATION defines a new collation using the specified operating system locale settings, or by copying an existing collation.

To be able to create a collation, you must haveCREATE privilege on the destination schema.

Parameters

IF NOT EXISTS

Do not throw an error if a collation with the same name already exists. A notice is issued in this case. Note that there is no guarantee that the existing collation is anything like the one that would have been created.

name

The name of the collation. The collation name can be schema-qualified. If it is not, the collation is defined in the current schema. The collation name must be unique within that schema. (The system catalogs can contain collations with the same name for other encodings, but these are ignored if the database encoding does not match.)

locale

The locale name for this collation. SeeSection 23.2.2.3.1 andSection 23.2.2.3.2 for details.

Ifprovider islibc, this is a shortcut for settingLC_COLLATE andLC_CTYPE at once. If you specifylocale, you cannot specify either of those parameters.

Ifprovider isbuiltin, thenlocale must be specified and set to eitherC orC.UTF-8.

lc_collate

Ifprovider islibc, use the specified operating system locale for theLC_COLLATE locale category.

lc_ctype

Ifprovider islibc, use the specified operating system locale for theLC_CTYPE locale category.

provider

Specifies the provider to use for locale services associated with this collation. Possible values arebuiltin,icu (if the server was built with ICU support) orlibc.libc is the default. SeeSection 23.1.4 for details.

DETERMINISTIC

Specifies whether the collation should use deterministic comparisons. The default is true. A deterministic comparison considers strings that are not byte-wise equal to be unequal even if they are considered logically equal by the comparison. PostgreSQL breaks ties using a byte-wise comparison. Comparison that is not deterministic can make the collation be, say, case- or accent-insensitive. For that, you need to choose an appropriateLOCALE settingand set the collation to not deterministic here.

Nondeterministic collations are only supported with the ICU provider.

rules

Specifies additional collation rules to customize the behavior of the collation. This is supported for ICU only. SeeSection 23.2.3.4 for details.

version

Specifies the version string to store with the collation. Normally, this should be omitted, which will cause the version to be computed from the actual version of the collation as provided by the operating system. This option is intended to be used bypg_upgrade for copying the version from an existing installation.

See alsoALTER COLLATION for how to handle collation version mismatches.

existing_collation

The name of an existing collation to copy. The new collation will have the same properties as the existing one, but it will be an independent object.

Notes

CREATE COLLATION takes aSHARE ROW EXCLUSIVE lock, which is self-conflicting, on thepg_collation system catalog, so only oneCREATE COLLATION command can run at a time.

UseDROP COLLATION to remove user-defined collations.

SeeSection 23.2.2.3 for more information on how to create collations.

When using thelibc collation provider, the locale must be applicable to the current database encoding. SeeCREATE DATABASE for the precise rules.

Examples

To create a collation from the operating system localefr_FR.utf8 (assuming the current database encoding isUTF8):

CREATE COLLATION french (locale = 'fr_FR.utf8');

To create a collation using the ICU provider using German phone book sort order:

CREATE COLLATION german_phonebook (provider = icu, locale = 'de-u-co-phonebk');

To create a collation using the ICU provider, based on the root ICU locale, with custom rules:

CREATE COLLATION custom (provider = icu, locale = 'und', rules = '&V << w <<< W');

SeeSection 23.2.3.4 for further details and examples on the rules syntax.

To create a collation from an existing collation:

CREATE COLLATION german FROM "de_DE";

This can be convenient to be able to use operating-system-independent collation names in applications.

Compatibility

There is aCREATE COLLATION statement in the SQL standard, but it is limited to copying an existing collation. The syntax to create a new collation is aPostgreSQL extension.


Prev Up Next
CREATE CAST Home CREATE CONVERSION
pdfepub
Go to PostgreSQL 17
By continuing to browse this website, you agree to the use of cookies. Go toPrivacy Policy.

[8]ページ先頭

©2009-2025 Movatter.jp