Home Explore Blog CI



postgresql

16th chunk of `doc/src/sgml/charset.sgml`
60c7976a80a3fcd9a072791801551dae9f5a61bbbf4114ca0000000100000fa4
 'de_DE');
</programlisting>
     The exact values that are acceptable for the <literal>locale</literal>
     clause in this command depend on the operating system.  On Unix-like
     systems, the command <literal>locale -a</literal> will show a list.
    </para>

    <para>
     Since the predefined libc collations already include all collations
     defined in the operating system when the database instance is
     initialized, it is not often necessary to manually create new ones.
     Reasons might be if a different naming system is desired (in which case
     see also <xref linkend="collation-copy"/>) or if the operating system has
     been upgraded to provide new locale definitions (in which case see
     also <link linkend="functions-admin-collation"><function>pg_import_system_collations()</function></link>).
    </para>
   </sect4>

   <sect4 id="collation-managing-create-icu">
    <title>ICU Collations</title>

    <para>
     ICU collations can be created like:

<programlisting>
CREATE COLLATION german (provider = icu, locale = 'de-DE');
</programlisting>

     ICU locales are specified as a BCP 47 <link
     linkend="icu-language-tag">Language Tag</link>, but can also accept most
     libc-style locale names. If possible, libc-style locale names are
     transformed into language tags.
    </para>
    <para>
     New ICU collations can customize collation behavior extensively by
     including collation attributes in the language tag. See <xref
     linkend="icu-custom-collations"/> for details and examples.
    </para>
   </sect4>
   <sect4 id="collation-copy">
   <title>Copying Collations</title>

   <para>
    The command <xref linkend="sql-createcollation"/> can also be used to
    create a new collation from an existing collation, which can be useful to
    be able to use operating-system-independent collation names in
    applications, create compatibility names, or use an ICU-provided collation
    under a more readable name.  For example:
<programlisting>
CREATE COLLATION german FROM "de_DE";
CREATE COLLATION french FROM "fr-x-icu";
</programlisting>
   </para>
   </sect4>
   </sect3>

   <sect3 id="collation-nondeterministic">
    <title>Nondeterministic Collations</title>

    <para>
     A collation is either <firstterm>deterministic</firstterm> or
     <firstterm>nondeterministic</firstterm>.  A deterministic collation uses
     deterministic comparisons, which means that it considers strings to be
     equal only if they consist of the same byte sequence.  Nondeterministic
     comparison may determine strings to be equal even if they consist of
     different bytes.  Typical situations include case-insensitive comparison,
     accent-insensitive comparison, as well as comparison of strings in
     different Unicode normal forms.  It is up to the collation provider to
     actually implement such insensitive comparisons; the deterministic flag
     only determines whether ties are to be broken using bytewise comparison.
     See also <ulink url="https://www.unicode.org/reports/tr10">Unicode Technical
     Standard 10</ulink> for more information on the terminology.
    </para>

    <para>
     To create a nondeterministic collation, specify the property
     <literal>deterministic = false</literal> to <command>CREATE
     COLLATION</command>, for example:
<programlisting>
CREATE COLLATION ndcoll (provider = icu, locale = 'und', deterministic = false);
</programlisting>
     This example would use the standard Unicode collation in a
     nondeterministic way.  In particular, this would allow strings in
     different normal forms to be compared correctly.  More interesting
     examples make use of the ICU customization facilities explained above.
     For example:
<programlisting>
CREATE COLLATION case_insensitive (provider = icu, locale = 'und-u-ks-level2', deterministic = false);
CREATE COLLATION ignore_accents (provider = icu, locale = 'und-u-ks-level1-kc-true', deterministic = false);
</programlisting>

Title: Customizing Collations
Summary
This section explains how to create custom collations, including ICU and libc collations, and how to customize their behavior using language tags and attributes, as well as how to create nondeterministic collations for case-insensitive, accent-insensitive, and other types of comparisons.