]> begriffs open source - ai-pg/blob - full-docs/html/sql-createcollation.html
Include links to all subsection html pages, with shorter paths too
[ai-pg] / full-docs / html / sql-createcollation.html
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>CREATE COLLATION</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="sql-createcast.html" title="CREATE CAST" /><link rel="next" href="sql-createconversion.html" title="CREATE CONVERSION" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">CREATE COLLATION</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-createcast.html" title="CREATE CAST">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><th width="60%" align="center">SQL Commands</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="sql-createconversion.html" title="CREATE CONVERSION">Next</a></td></tr></table><hr /></div><div class="refentry" id="SQL-CREATECOLLATION"><div class="titlepage"></div><a id="id-1.9.3.59.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">CREATE COLLATION</span></h2><p>CREATE COLLATION — define a new collation</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
3 CREATE COLLATION [ IF NOT EXISTS ] <em class="replaceable"><code>name</code></em> (
4     [ LOCALE = <em class="replaceable"><code>locale</code></em>, ]
5     [ LC_COLLATE = <em class="replaceable"><code>lc_collate</code></em>, ]
6     [ LC_CTYPE = <em class="replaceable"><code>lc_ctype</code></em>, ]
7     [ PROVIDER = <em class="replaceable"><code>provider</code></em>, ]
8     [ DETERMINISTIC = <em class="replaceable"><code>boolean</code></em>, ]
9     [ RULES = <em class="replaceable"><code>rules</code></em>, ]
10     [ VERSION = <em class="replaceable"><code>version</code></em> ]
11 )
12 CREATE COLLATION [ IF NOT EXISTS ] <em class="replaceable"><code>name</code></em> FROM <em class="replaceable"><code>existing_collation</code></em>
13 </pre></div><div class="refsect1" id="SQL-CREATECOLLATION-DESCRIPTION"><h2>Description</h2><p>
14    <code class="command">CREATE COLLATION</code> defines a new collation using
15    the specified operating system locale settings,
16    or by copying an existing collation.
17  </p><p>
18    To be able to create a collation, you must
19    have <code class="literal">CREATE</code> privilege on the destination schema.
20   </p></div><div class="refsect1" id="id-1.9.3.59.6"><h2>Parameters</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="literal">IF NOT EXISTS</code></span></dt><dd><p>
21        Do not throw an error if a collation with the same name already exists.
22        A notice is issued in this case. Note that there is no guarantee that
23        the existing collation is anything like the one that would have been created.
24       </p></dd><dt><span class="term"><em class="replaceable"><code>name</code></em></span></dt><dd><p>
25        The name of the collation. The collation name can be
26        schema-qualified. If it is not, the collation is defined in the
27        current schema. The collation name must be unique within that
28        schema.  (The system catalogs can contain collations with the
29        same name for other encodings, but these are ignored if the
30        database encoding does not match.)
31       </p></dd><dt><span class="term"><em class="replaceable"><code>locale</code></em></span></dt><dd><p>
32        The locale name for this collation. See <a class="xref" href="collation.html#COLLATION-MANAGING-CREATE-LIBC" title="23.2.2.3.1. libc Collations">Section 23.2.2.3.1</a> and <a class="xref" href="collation.html#COLLATION-MANAGING-CREATE-ICU" title="23.2.2.3.2. ICU Collations">Section 23.2.2.3.2</a> for details.
33       </p><p>
34        If <em class="replaceable"><code>provider</code></em> is <code class="literal">libc</code>, this
35        is a shortcut for setting <code class="symbol">LC_COLLATE</code> and
36        <code class="symbol">LC_CTYPE</code> at once.  If you specify
37        <em class="replaceable"><code>locale</code></em>, you cannot specify either of those
38        parameters.
39       </p><p>
40        If <em class="replaceable"><code>provider</code></em> is <code class="literal">builtin</code>,
41        then <em class="replaceable"><code>locale</code></em> must be specified and set to
42        either <code class="literal">C</code>, <code class="literal">C.UTF-8</code> or
43        <code class="literal">PG_UNICODE_FAST</code>.
44       </p></dd><dt><span class="term"><em class="replaceable"><code>lc_collate</code></em></span></dt><dd><p>
45        If <em class="replaceable"><code>provider</code></em> is <code class="literal">libc</code>, use
46        the specified operating system locale for the
47        <code class="symbol">LC_COLLATE</code> locale category.
48       </p></dd><dt><span class="term"><em class="replaceable"><code>lc_ctype</code></em></span></dt><dd><p>
49        If <em class="replaceable"><code>provider</code></em> is <code class="literal">libc</code>, use
50        the specified operating system locale for the <code class="symbol">LC_CTYPE</code>
51        locale category.
52       </p></dd><dt><span class="term"><em class="replaceable"><code>provider</code></em></span></dt><dd><p>
53        Specifies the provider to use for locale services associated with this
54        collation.  Possible values are <code class="literal">builtin</code>,
55        <code class="literal">icu</code><a id="id-1.9.3.59.6.2.6.2.1.3" class="indexterm"></a> (if
56        the server was built with ICU support) or <code class="literal">libc</code>.
57        <code class="literal">libc</code> is the default.  See <a class="xref" href="locale.html#LOCALE-PROVIDERS" title="23.1.4. Locale Providers">Section 23.1.4</a> for details.
58       </p></dd><dt><span class="term"><code class="literal">DETERMINISTIC</code></span></dt><dd><p>
59        Specifies whether the collation should use deterministic comparisons.
60        The default is true.  A deterministic comparison considers strings that
61        are not byte-wise equal to be unequal even if they are considered
62        logically equal by the comparison.  PostgreSQL breaks ties using a
63        byte-wise comparison.  Comparison that is not deterministic can make the
64        collation be, say, case- or accent-insensitive.  For that, you need to
65        choose an appropriate <code class="literal">LOCALE</code> setting
66        <span class="emphasis"><em>and</em></span> set the collation to not deterministic here.
67       </p><p>
68        Nondeterministic collations are only supported with the ICU provider.
69       </p></dd><dt><span class="term"><em class="replaceable"><code>rules</code></em></span></dt><dd><p>
70        Specifies additional collation rules to customize the behavior of the
71        collation.  This is supported for ICU only.  See <a class="xref" href="collation.html#ICU-TAILORING-RULES" title="23.2.3.4. ICU Tailoring Rules">Section 23.2.3.4</a> for details.
72       </p></dd><dt><span class="term"><em class="replaceable"><code>version</code></em></span></dt><dd><p>
73        Specifies the version string to store with the collation.  Normally,
74        this should be omitted, which will cause the version to be computed
75        from the actual version of the collation as provided by the operating
76        system.  This option is intended to be used
77        by <code class="command">pg_upgrade</code> for copying the version from an
78        existing installation.
79       </p><p>
80        See also <a class="xref" href="sql-altercollation.html" title="ALTER COLLATION"><span class="refentrytitle">ALTER COLLATION</span></a> for how to handle
81        collation version mismatches.
82       </p></dd><dt><span class="term"><em class="replaceable"><code>existing_collation</code></em></span></dt><dd><p>
83        The name of an existing collation to copy.  The new collation
84        will have the same properties as the existing one, but it
85        will be an independent object.
86       </p></dd></dl></div></div><div class="refsect1" id="SQL-CREATECOLLATION-NOTES"><h2>Notes</h2><p>
87    <code class="command">CREATE COLLATION</code> takes a <code class="literal">SHARE ROW
88    EXCLUSIVE</code> lock, which is self-conflicting, on the
89    <code class="structname">pg_collation</code> system catalog, so only one
90    <code class="command">CREATE COLLATION</code> command can run at a time.
91   </p><p>
92    Use <code class="command">DROP COLLATION</code> to remove user-defined collations.
93   </p><p>
94    See <a class="xref" href="collation.html#COLLATION-CREATE" title="23.2.2.3. Creating New Collation Objects">Section 23.2.2.3</a> for more information on how to create collations.
95   </p><p>
96    When using the <code class="literal">libc</code> collation provider, the locale must
97    be applicable to the current database encoding.
98    See <a class="xref" href="sql-createdatabase.html" title="CREATE DATABASE"><span class="refentrytitle">CREATE DATABASE</span></a> for the precise rules.
99   </p></div><div class="refsect1" id="SQL-CREATECOLLATION-EXAMPLES"><h2>Examples</h2><p>
100    To create a collation from the operating system locale
101    <code class="literal">fr_FR.utf8</code>
102    (assuming the current database encoding is <code class="literal">UTF8</code>):
103 </p><pre class="programlisting">
104 CREATE COLLATION french (locale = 'fr_FR.utf8');
105 </pre><p>
106   </p><p>
107    To create a collation using the ICU provider using German phone book sort order:
108 </p><pre class="programlisting">
109 CREATE COLLATION german_phonebook (provider = icu, locale = 'de-u-co-phonebk');
110 </pre><p>
111   </p><p>
112    To create a collation using the ICU provider, based on the root ICU locale,
113    with custom rules:
114 </p><pre class="programlisting">
115 CREATE COLLATION custom (provider = icu, locale = 'und', rules = '&amp;V &lt;&lt; w &lt;&lt;&lt; W');
116 </pre><p>
117    See <a class="xref" href="collation.html#ICU-TAILORING-RULES" title="23.2.3.4. ICU Tailoring Rules">Section 23.2.3.4</a> for further details and examples
118    on the rules syntax.
119   </p><p>
120    To create a collation from an existing collation:
121 </p><pre class="programlisting">
122 CREATE COLLATION german FROM "de_DE";
123 </pre><p>
124    This can be convenient to be able to use operating-system-independent
125    collation names in applications.
126   </p></div><div class="refsect1" id="SQL-CREATECOLLATION-COMPAT"><h2>Compatibility</h2><p>
127    There is a <code class="command">CREATE COLLATION</code> statement in the SQL
128    standard, but it is limited to copying an existing collation.  The
129    syntax to create a new collation is
130    a <span class="productname">PostgreSQL</span> extension.
131   </p></div><div class="refsect1" id="SQL-CREATECOLLATION-SEEALSO"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-altercollation.html" title="ALTER COLLATION"><span class="refentrytitle">ALTER COLLATION</span></a>, <a class="xref" href="sql-dropcollation.html" title="DROP COLLATION"><span class="refentrytitle">DROP COLLATION</span></a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sql-createcast.html" title="CREATE CAST">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-createconversion.html" title="CREATE CONVERSION">Next</a></td></tr><tr><td width="40%" align="left" valign="top">CREATE CAST </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> CREATE CONVERSION</td></tr></table></div></body></html>