バージョンごとのドキュメント一覧

CREATE COLLATION

CREATE COLLATION <refpurpose>define a new collation</refpurpose> — 新しい照合順序を定義する

概要

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 FROM existing_collation

説明

<title>Description</title>

<command>CREATE COLLATION</command> defines a new collation using the specified operating system locale settings, or by copying an existing collation. CREATE COLLATIONは指定したオペレーティングシステムのロケール設定を使用、または既存の照合順序をコピーすることで新しい照合順序を定義します。

To be able to create a collation, you must have <literal>CREATE</literal> privilege on the destination schema. 照合順序を新しく作成するためには、格納先のスキーマにおけるCREATE権限が必要です。

パラメータ

<title>Parameters</title>
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. See <xref linkend="collation-managing-create-libc"/> and <xref linkend="collation-managing-create-icu"/> for details. この照合順序のロケール名です。 詳しくは24.2.2.3.124.2.2.3.2を見てください。

If <replaceable>provider</replaceable> is <literal>libc</literal>, this is a shortcut for setting <symbol>LC_COLLATE</symbol> and <symbol>LC_CTYPE</symbol> at once. If you specify <replaceable>locale</replaceable>, you cannot specify either of those parameters. providerlibcなら、これは同時にLC_COLLATEおよびLC_CTYPEを設定する省略形です。 localeを指定した場合、これらのパラメータのどちらも指定できません。

lc_collate

If <replaceable>provider</replaceable> is <literal>libc</literal>, use the specified operating system locale for the <symbol>LC_COLLATE</symbol> locale category. providerlibcなら、LC_COLLATEロケールカテゴリに対して指定したオペレーティングシステムのロケールを使用します。

lc_ctype

If <replaceable>provider</replaceable> is <literal>libc</literal>, use the specified operating system locale for the <symbol>LC_CTYPE</symbol> locale category. providerlibcなら、LC_CTYPEロケールカテゴリに対して指定したオペレーティングシステムのロケールを使用します。

provider

Specifies the provider to use for locale services associated with this collation. Possible values are <literal>icu</literal><indexterm><primary>ICU</primary></indexterm> (if the server was built with ICU support) or <literal>libc</literal>. <literal>libc</literal> is the default. See <xref linkend="locale-providers"/> for details. この照合順序に関連するロケールサービスで使用するプロバイダを指定します。 取り得る値はicu(サーバがICUサポートで構築されている場合)とlibcです。 libcがデフォルトです。 詳しくは24.1.4を参照してください。

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 appropriate <literal>LC_COLLATE</literal> setting <emphasis>and</emphasis> set the collation to not deterministic here. 照合順序が決定論的な比較を使うかどうかを指定します。 デフォルトは真です。 決定論的な比較では、たとえ論理的に比較すれば等しいとみなされるものであっても、バイト単位で等しくない文字列は等しくないとみなします。 PostgreSQLはバイト単位の比較を使って分解します。 決定論的でない比較では、例えば、照合順序で大文字小文字を区別しない、またはアクセントを区別しないようにできます。 そのためには、適切なLC_COLLATEの設定を選んだ上で、ここで照合順序を非決定論的なものに設定することが必要です。

Nondeterministic collations are only supported with the ICU provider. 非決定論的な照合順序はICUプロバイダでのみサポートされています。

rules

Specifies additional collation rules to customize the behavior of the collation. This is supported for ICU only. See <xref linkend="icu-tailoring-rules"/> for details. 照合順序の動作をカスタマイズするための追加の照合順序規則を指定します。 これはICUでのみサポートされています。 詳細は24.2.3.4を参照してください。

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 by <command>pg_upgrade</command> for copying the version from an existing installation. 照合順序と一緒に保存するバージョン文字列を指定します。 通常は省略すべきで、省略するとオペレーティングシステムが提供する照合順序の実際のバージョンから計算されます。 このオプションはpg_upgradeが既存のインストレーションからバージョンをコピーする時に使われることを意図したものです。

See also <xref linkend="sql-altercollation"/> for how to handle collation version mismatches. 照合順序のバージョン不適合を処理する方法については、ALTER COLLATIONも参照してください。

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. コピーする既存の照合順序の名前です。 新しい照合順序は既存のものと同じ属性を持ちますが、独立したオブジェクトになります。

注釈

<title>Notes</title>

<command>CREATE COLLATION</command> takes a <literal>SHARE ROW EXCLUSIVE</literal> lock, which is self-conflicting, on the <structname>pg_collation</structname> system catalog, so only one <command>CREATE COLLATION</command> command can run at a time. CREATE COLLATIONSHARE ROW EXCLUSIVEロックを使い、そのロックはpg_collationシステムカタログで衝突します。ですので、CREATE COLLATIONは一度に1つしか実行できません。

Use <command>DROP COLLATION</command> to remove user-defined collations. ユーザ定義の照合順序を削除するためにはDROP COLLATIONを使用してください。

See <xref linkend="collation-create"/> for more information on how to create collations. 照合順序の作成についての更なる情報については24.2.2.3を参照してください。

When using the <literal>libc</literal> collation provider, the locale must be applicable to the current database encoding. See <xref linkend="sql-createdatabase"/> for the precise rules. libc照合順序プロバイダを使う場合、ロケールは現在のデータベース符号化方式に適用可能でなければなりません。 正確な規則についてはCREATE DATABASEを参照してください。

<title>Examples</title>

To create a collation from the operating system locale <literal>fr_FR.utf8</literal> (assuming the current database encoding is <literal>UTF8</literal>): オペレーティングシステムのロケールfr_FR.utf8から照合順序を作成します (現在のデータベース符号化方式がUTF8であるとします)。

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

To create a collation using the ICU provider using German phone book sort order: ICUプロバイダを使い、ドイツの電話帳のソート順を使った照合順序を作成します。

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: ICUプロバイダを使い、ルートICUロケールに基づいて、カスタム規則を使って照合順序を作成するには、次のようにします。

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

See <xref linkend="icu-tailoring-rules"/> for further details and examples on the rules syntax. 規則の構文の詳細と例については、24.2.3.4を参照してください。

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. アプリケーションにおいてオペレーティングシステムに依存しない照合順序の名前を使用することができ、便利になるかもしれません。

互換性

<title>Compatibility</title>

There is a <command>CREATE COLLATION</command> statement in the SQL standard, but it is limited to copying an existing collation. The syntax to create a new collation is a <productname>PostgreSQL</productname> extension. 標準SQLにはCREATE COLLATIONが存在しますが、既存の照合順序のコピーに限定されています。 新しい照合順序を作成するための構文はPostgreSQLの拡張です。

関連項目

<title>See Also</title> ALTER COLLATION, DROP COLLATION