codekingpro/portable-devtools
115k
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 16.3 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">3CREATE 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)12CREATE 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 using15 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 must19 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 that23 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 be26 schema-qualified. If it is not, the collation is defined in the27 current schema. The collation name must be unique within that28 schema. (The system catalogs can contain collations with the29 same name for other encodings, but these are ignored if the30 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="24.2.2.3.1. libc Collations">Section 24.2.2.3.1</a> and <a class="xref" href="collation.html#COLLATION-MANAGING-CREATE-ICU" title="24.2.2.3.2. ICU Collations">Section 24.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>, this35 is a shortcut for setting <code class="symbol">LC_COLLATE</code> and36 <code class="symbol">LC_CTYPE</code> at once. If you specify37 <em class="replaceable"><code>locale</code></em>, you cannot specify either of those38 parameters.39 </p></dd><dt><span class="term"><em class="replaceable"><code>lc_collate</code></em></span></dt><dd><p>40 If <em class="replaceable"><code>provider</code></em> is <code class="literal">libc</code>, use41 the specified operating system locale for the42 <code class="symbol">LC_COLLATE</code> locale category.43 </p></dd><dt><span class="term"><em class="replaceable"><code>lc_ctype</code></em></span></dt><dd><p>44 If <em class="replaceable"><code>provider</code></em> is <code class="literal">libc</code>, use45 the specified operating system locale for the <code class="symbol">LC_CTYPE</code>46 locale category.47 </p></dd><dt><span class="term"><em class="replaceable"><code>provider</code></em></span></dt><dd><p>48 Specifies the provider to use for locale services associated with this49 collation. Possible values are50 <code class="literal">icu</code><a id="id-1.9.3.59.6.2.6.2.1.2" class="indexterm"></a>51 (if the server was built with ICU support) or <code class="literal">libc</code>.52 <code class="literal">libc</code> is the default. See <a class="xref" href="locale.html#LOCALE-PROVIDERS" title="24.1.4. Locale Providers">Section 24.1.4</a> for details.53 </p></dd><dt><span class="term"><code class="literal">DETERMINISTIC</code></span></dt><dd><p>54 Specifies whether the collation should use deterministic comparisons.55 The default is true. A deterministic comparison considers strings that56 are not byte-wise equal to be unequal even if they are considered57 logically equal by the comparison. PostgreSQL breaks ties using a58 byte-wise comparison. Comparison that is not deterministic can make the59 collation be, say, case- or accent-insensitive. For that, you need to60 choose an appropriate <code class="literal">LOCALE</code> setting61 <span class="emphasis"><em>and</em></span> set the collation to not deterministic here.62 </p><p>63 Nondeterministic collations are only supported with the ICU provider.64 </p></dd><dt><span class="term"><em class="replaceable"><code>rules</code></em></span></dt><dd><p>65 Specifies additional collation rules to customize the behavior of the66 collation. This is supported for ICU only. See <a class="xref" href="collation.html#ICU-TAILORING-RULES" title="24.2.3.4. ICU Tailoring Rules">Section 24.2.3.4</a> for details.67 </p></dd><dt><span class="term"><em class="replaceable"><code>version</code></em></span></dt><dd><p>68 Specifies the version string to store with the collation. Normally,69 this should be omitted, which will cause the version to be computed70 from the actual version of the collation as provided by the operating71 system. This option is intended to be used72 by <code class="command">pg_upgrade</code> for copying the version from an73 existing installation.74 </p><p>75 See also <a class="xref" href="sql-altercollation.html" title="ALTER COLLATION"><span class="refentrytitle">ALTER COLLATION</span></a> for how to handle76 collation version mismatches.77 </p></dd><dt><span class="term"><em class="replaceable"><code>existing_collation</code></em></span></dt><dd><p>78 The name of an existing collation to copy. The new collation79 will have the same properties as the existing one, but it80 will be an independent object.81 </p></dd></dl></div></div><div class="refsect1" id="SQL-CREATECOLLATION-NOTES"><h2>Notes</h2><p>82 <code class="command">CREATE COLLATION</code> takes a <code class="literal">SHARE ROW83 EXCLUSIVE</code> lock, which is self-conflicting, on the84 <code class="structname">pg_collation</code> system catalog, so only one85 <code class="command">CREATE COLLATION</code> command can run at a time.86 </p><p>87 Use <code class="command">DROP COLLATION</code> to remove user-defined collations.88 </p><p>89 See <a class="xref" href="collation.html#COLLATION-CREATE" title="24.2.2.3. Creating New Collation Objects">Section 24.2.2.3</a> for more information on how to create collations.90 </p><p>91 When using the <code class="literal">libc</code> collation provider, the locale must92 be applicable to the current database encoding.93 See <a class="xref" href="sql-createdatabase.html" title="CREATE DATABASE"><span class="refentrytitle">CREATE DATABASE</span></a> for the precise rules.94 </p></div><div class="refsect1" id="SQL-CREATECOLLATION-EXAMPLES"><h2>Examples</h2><p>95 To create a collation from the operating system locale96 <code class="literal">fr_FR.utf8</code>97 (assuming the current database encoding is <code class="literal">UTF8</code>):98</p><pre class="programlisting">99CREATE COLLATION french (locale = 'fr_FR.utf8');100</pre><p>101 </p><p>102 To create a collation using the ICU provider using German phone book sort order:103</p><pre class="programlisting">104CREATE COLLATION german_phonebook (provider = icu, locale = 'de-u-co-phonebk');105</pre><p>106 </p><p>107 To create a collation using the ICU provider, based on the root ICU locale,108 with custom rules:109</p><pre class="programlisting">110CREATE COLLATION custom (provider = icu, locale = 'und', rules = '&V << w <<< W');111</pre><p>112 See <a class="xref" href="collation.html#ICU-TAILORING-RULES" title="24.2.3.4. ICU Tailoring Rules">Section 24.2.3.4</a> for further details and examples113 on the rules syntax.114 </p><p>115 To create a collation from an existing collation:116</p><pre class="programlisting">117CREATE COLLATION german FROM "de_DE";118</pre><p>119 This can be convenient to be able to use operating-system-independent120 collation names in applications.121 </p></div><div class="refsect1" id="SQL-CREATECOLLATION-COMPAT"><h2>Compatibility</h2><p>122 There is a <code class="command">CREATE COLLATION</code> statement in the SQL123 standard, but it is limited to copying an existing collation. The124 syntax to create a new collation is125 a <span class="productname">PostgreSQL</span> extension.126 </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 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> CREATE CONVERSION</td></tr></table></div></body></html>