Debian Codegraph @

doc/src/sgml/charset.sgml

raw
1 <!-- doc/src/sgml/charset.sgml -->
2
3 <chapter id="charset">
4 <title>Localization</title>
5
6 <para>
7 This chapter describes the available localization features from the
8 point of view of the administrator.
9 <productname>PostgreSQL</productname> supports two localization
10 facilities:
11
12 <itemizedlist>
13 <listitem>
14 <para>
15 Using the locale features of the operating system to provide
16 locale-specific collation order, number formatting, translated
17 messages, and other aspects.
18 This is covered in <xref linkend="locale"/> and
19 <xref linkend="collation"/>.
20 </para>
21 </listitem>
22
23 <listitem>
24 <para>
25 Providing a number of different character sets to support storing text
26 in all kinds of languages, and providing character set translation
27 between client and server.
28 This is covered in <xref linkend="multibyte"/>.
29 </para>
30 </listitem>
31 </itemizedlist>
32 </para>
33
34
35 <sect1 id="locale">
36 <title>Locale Support</title>
37
38 <indexterm zone="locale"><primary>locale</primary></indexterm>
39
40 <para>
41 <firstterm>Locale</firstterm> support refers to an application respecting
42 cultural preferences regarding alphabets, sorting, number
43 formatting, etc. <productname>PostgreSQL</productname> uses the standard ISO
44 C and <acronym>POSIX</acronym> locale facilities provided by the server operating
45 system. For additional information refer to the documentation of your
46 system.
47 </para>
48
49 <sect2 id="locale-overview">
50 <title>Overview</title>
51
52 <para>
53 Locale support is automatically initialized when a database
54 cluster is created using <command>initdb</command>.
55 <command>initdb</command> will initialize the database cluster
56 with the locale setting of its execution environment by default,
57 so if your system is already set to use the locale that you want
58 in your database cluster then there is nothing else you need to
59 do. If you want to use a different locale (or you are not sure
60 which locale your system is set to), you can instruct
61 <command>initdb</command> exactly which locale to use by
62 specifying the <option>--locale</option> option. For example:
63 <screen>
64 initdb --locale=sv_SE
65 </screen>
66 </para>
67
68 <para>
69 This example for Unix systems sets the locale to Swedish
70 (<literal>sv</literal>) as spoken
71 in Sweden (<literal>SE</literal>). Other possibilities might include
72 <literal>en_US</literal> (U.S. English) and <literal>fr_CA</literal> (French
73 Canadian). If more than one character set can be used for a
74 locale then the specifications can take the form
75 <replaceable>language_territory.codeset</replaceable>. For example,
76 <literal>fr_BE.UTF-8</literal> represents the French language (fr) as
77 spoken in Belgium (BE), with a <acronym>UTF-8</acronym> character set
78 encoding.
79 </para>
80
81 <para>
82 What locales are available on your
83 system under what names depends on what was provided by the operating
84 system vendor and what was installed. On most Unix systems, the command
85 <literal>locale -a</literal> will provide a list of available locales.
86 Windows uses more verbose locale names, such as <literal>German_Germany</literal>
87 or <literal>Swedish_Sweden.1252</literal>, but the principles are the same.
88 </para>
89
90 <para>
91 Occasionally it is useful to mix rules from several locales, e.g.,
92 use English collation rules but Spanish messages. To support that, a
93 set of locale subcategories exist that control only certain
94 aspects of the localization rules:
95
96 <informaltable>
97 <tgroup cols="2">
98 <colspec colname="col1" colwidth="1*"/>
99 <colspec colname="col2" colwidth="3*"/>
100 <tbody>
101 <row>
102 <entry><envar>LC_COLLATE</envar></entry>
103 <entry>String sort order</entry>
104 </row>
105 <row>
106 <entry><envar>LC_CTYPE</envar></entry>
107 <entry>Character classification (What is a letter? Its upper-case equivalent?)</entry>
108 </row>
109 <row>
110 <entry><envar>LC_MESSAGES</envar></entry>
111 <entry>Language of messages</entry>
112 </row>
113 <row>
114 <entry><envar>LC_MONETARY</envar></entry>
115 <entry>Formatting of currency amounts</entry>
116 </row>
117 <row>
118 <entry><envar>LC_NUMERIC</envar></entry>
119 <entry>Formatting of numbers</entry>
120 </row>
121 <row>
122 <entry><envar>LC_TIME</envar></entry>
123 <entry>Formatting of dates and times</entry>
124 </row>
125 </tbody>
126 </tgroup>
127 </informaltable>
128
129 The category names translate into names of
130 <command>initdb</command> options to override the locale choice
131 for a specific category. For instance, to set the locale to
132 French Canadian, but use U.S. rules for formatting currency, use
133 <literal>initdb --locale=fr_CA --lc-monetary=en_US</literal>.
134 </para>
135
136 <para>
137 If you want the system to behave as if it had no locale support,
138 use the special locale name <literal>C</literal>, or equivalently
139 <literal>POSIX</literal>.
140 </para>
141
142 <para>
143 Some locale categories must have their values
144 fixed when the database is created. You can use different settings
145 for different databases, but once a database is created, you cannot
146 change them for that database anymore. <literal>LC_COLLATE</literal>
147 and <literal>LC_CTYPE</literal> are these categories. They affect
148 the sort order of indexes, so they must be kept fixed, or indexes on
149 text columns would become corrupt.
150 (But you can alleviate this restriction using collations, as discussed
151 in <xref linkend="collation"/>.)
152 The default values for these
153 categories are determined when <command>initdb</command> is run, and
154 those values are used when new databases are created, unless
155 specified otherwise in the <command>CREATE DATABASE</command> command.
156 </para>
157
158 <para>
159 The other locale categories can be changed whenever desired
160 by setting the server configuration parameters
161 that have the same name as the locale categories (see <xref
162 linkend="runtime-config-client-format"/> for details). The values
163 that are chosen by <command>initdb</command> are actually only written
164 into the configuration file <filename>postgresql.conf</filename> to
165 serve as defaults when the server is started. If you remove these
166 assignments from <filename>postgresql.conf</filename> then the
167 server will inherit the settings from its execution environment.
168 </para>
169
170 <para>
171 Note that the locale behavior of the server is determined by the
172 environment variables seen by the server, not by the environment
173 of any client. Therefore, be careful to configure the correct locale settings
174 before starting the server. A consequence of this is that if
175 client and server are set up in different locales, messages might
176 appear in different languages depending on where they originated.
177 </para>
178
179 <note>
180 <para>
181 When we speak of inheriting the locale from the execution
182 environment, this means the following on most operating systems:
183 For a given locale category, say the collation, the following
184 environment variables are consulted in this order until one is
185 found to be set: <envar>LC_ALL</envar>, <envar>LC_COLLATE</envar>
186 (or the variable corresponding to the respective category),
187 <envar>LANG</envar>. If none of these environment variables are
188 set then the locale defaults to <literal>C</literal>.
189 </para>
190
191 <para>
192 Some message localization libraries also look at the environment
193 variable <envar>LANGUAGE</envar> which overrides all other locale
194 settings for the purpose of setting the language of messages. If
195 in doubt, please refer to the documentation of your operating
196 system, in particular the documentation about
197 <application>gettext</application>.
198 </para>
199 </note>
200
201 <para>
202 To enable messages to be translated to the user's preferred language,
203 <acronym>NLS</acronym> must have been selected at build time
204 (<literal>configure --enable-nls</literal>). All other locale support is
205 built in automatically.
206 </para>
207 </sect2>
208
209 <sect2 id="locale-behavior">
210 <title>Behavior</title>
211
212 <para>
213 The locale settings influence the following SQL features:
214
215 <itemizedlist>
216 <listitem>
217 <para>
218 Sort order in queries using <literal>ORDER BY</literal> or the standard
219 comparison operators on textual data
220 <indexterm><primary>ORDER BY</primary><secondary>and locales</secondary></indexterm>
221 </para>
222 </listitem>
223
224 <listitem>
225 <para>
226 The <function>upper</function>, <function>lower</function>, and <function>initcap</function>
227 functions
228 <indexterm><primary>upper</primary><secondary>and locales</secondary></indexterm>
229 <indexterm><primary>lower</primary><secondary>and locales</secondary></indexterm>
230 </para>
231 </listitem>
232
233 <listitem>
234 <para>
235 Pattern matching operators (<literal>LIKE</literal>, <literal>SIMILAR TO</literal>,
236 and POSIX-style regular expressions); locales affect both case
237 insensitive matching and the classification of characters by
238 character-class regular expressions
239 <indexterm><primary>LIKE</primary><secondary>and locales</secondary></indexterm>
240 <indexterm><primary>regular expressions</primary><secondary>and locales</secondary></indexterm>
241 </para>
242 </listitem>
243
244 <listitem>
245 <para>
246 The <function>to_char</function> family of functions
247 <indexterm><primary>to_char</primary><secondary>and locales</secondary></indexterm>
248 </para>
249 </listitem>
250
251 <listitem>
252 <para>
253 The ability to use indexes with <literal>LIKE</literal> clauses
254 </para>
255 </listitem>
256 </itemizedlist>
257 </para>
258
259 <para>
260 The drawback of using locales other than <literal>C</literal> or
261 <literal>POSIX</literal> in <productname>PostgreSQL</productname> is its performance
262 impact. It slows character handling and prevents ordinary indexes
263 from being used by <literal>LIKE</literal>. For this reason use locales
264 only if you actually need them.
265 </para>
266
267 <para>
268 As a workaround to allow <productname>PostgreSQL</productname> to use indexes
269 with <literal>LIKE</literal> clauses under a non-C locale, several custom
270 operator classes exist. These allow the creation of an index that
271 performs a strict character-by-character comparison, ignoring
272 locale comparison rules. Refer to <xref linkend="indexes-opclass"/>
273 for more information. Another approach is to create indexes using
274 the <literal>C</literal> collation, as discussed in
275 <xref linkend="collation"/>.
276 </para>
277 </sect2>
278
279 <sect2 id="locale-selecting-locales">
280 <title>Selecting Locales</title>
281
282 <para>
283 Locales can be selected in different scopes depending on requirements.
284 The above overview showed how locales are specified using
285 <command>initdb</command> to set the defaults for the entire cluster. The
286 following list shows where locales can be selected. Each item provides
287 the defaults for the subsequent items, and each lower item allows
288 overriding the defaults on a finer granularity.
289 </para>
290
291 <orderedlist>
292 <listitem>
293 <para>
294 As explained above, the environment of the operating system provides the
295 defaults for the locales of a newly initialized database cluster. In
296 many cases, this is enough: if the operating system is configured for
297 the desired language/territory, by default
298 <productname>PostgreSQL</productname> will also behave according
299 to that locale.
300 </para>
301 </listitem>
302
303 <listitem>
304 <para>
305 As shown above, command-line options for <command>initdb</command>
306 specify the locale settings for a newly initialized database cluster.
307 Use this if the operating system does not have the locale configuration
308 you want for your database system.
309 </para>
310 </listitem>
311
312 <listitem>
313 <para>
314 A locale can be selected separately for each database. The SQL command
315 <command>CREATE DATABASE</command> and its command-line equivalent
316 <command>createdb</command> have options for that. Use this for example
317 if a database cluster houses databases for multiple tenants with
318 different requirements.
319 </para>
320 </listitem>
321
322 <listitem>
323 <para>
324 Locale settings can be made for individual table columns. This uses an
325 SQL object called <firstterm>collation</firstterm> and is explained in
326 <xref linkend="collation"/>. Use this for example to sort data in
327 different languages or customize the sort order of a particular table.
328 </para>
329 </listitem>
330
331 <listitem>
332 <para>
333 Finally, locales can be selected for an individual query. Again, this
334 uses SQL collation objects. This could be used to change the sort order
335 based on run-time choices or for ad-hoc experimentation.
336 </para>
337 </listitem>
338 </orderedlist>
339 </sect2>
340
341 <sect2 id="locale-providers">
342 <title>Locale Providers</title>
343
344 <para>
345 A locale provider specifies which library defines the locale behavior for
346 collations and character classifications.
347 </para>
348
349 <para>
350 The commands and tools that select the locale settings, as described
351 above, each have an option to select the locale provider. Here is an
352 example to initialize a database cluster using the ICU provider:
353 <programlisting>
354 initdb --locale-provider=icu --icu-locale=en
355 </programlisting>
356 See the description of the respective commands and programs for
357 details. Note that you can mix locale providers at different
358 granularities, for example use <literal>libc</literal> by default for the
359 cluster but have one database that uses the <literal>icu</literal>
360 provider, and then have collation objects using either provider within
361 those databases.
362 </para>
363
364 <para>
365 Regardless of the locale provider, the operating system is still used to
366 provide some locale-aware behavior, such as messages (see <xref
367 linkend="guc-lc-messages"/>).
368 </para>
369
370 <para>
371 The available locale providers are listed below:
372 </para>
373
374 <variablelist>
375 <varlistentry>
376 <term><literal>builtin</literal></term>
377 <listitem>
378 <para>
379 The <literal>builtin</literal> provider uses built-in operations. Only
380 the <literal>C</literal>, <literal>C.UTF-8</literal>, and
381 <literal>PG_UNICODE_FAST</literal> locales are supported for this
382 provider.
383 </para>
384 <para>
385 The <literal>C</literal> locale behavior is identical to the
386 <literal>C</literal> locale in the libc provider. When using this
387 locale, the behavior may depend on the database encoding.
388 </para>
389 <para>
390 The <literal>C.UTF-8</literal> locale is available only for when the
391 database encoding is <literal>UTF-8</literal>, and the behavior is
392 based on Unicode. The collation uses the code point values only. The
393 regular expression character classes are based on the "POSIX
394 Compatible" semantics, and the case mapping is the "simple" variant.
395 </para>
396 <para>
397 The <literal>PG_UNICODE_FAST</literal> locale is available only when
398 the database encoding is <literal>UTF-8</literal>, and the behavior is
399 based on Unicode. The collation uses the code point values only. The
400 regular expression character classes are based on the "Standard"
401 semantics, and the case mapping is the "full" variant.
402 </para>
403 </listitem>
404 </varlistentry>
405
406 <varlistentry>
407 <term><literal>icu</literal></term>
408 <listitem>
409 <para>
410 The <literal>icu</literal> provider uses the external
411 ICU<indexterm><primary>ICU</primary></indexterm>
412 library. <productname>PostgreSQL</productname> must have been
413 configured with support.
414 </para>
415 <para>
416 ICU provides collation and character classification behavior that is
417 independent of the operating system and database encoding, which is
418 preferable if you expect to transition to other platforms without any
419 change in results. <literal>LC_COLLATE</literal> and
420 <literal>LC_CTYPE</literal> can be set independently of the ICU
421 locale.
422 </para>
423 <note>
424 <para>
425 For the ICU provider, results may depend on the version of the ICU
426 library used, as it is updated to reflect changes in natural language
427 over time.
428 </para>
429 </note>
430 </listitem>
431 </varlistentry>
432
433 <varlistentry>
434 <term><literal>libc</literal></term>
435 <listitem>
436 <para>
437 The <literal>libc</literal> provider uses the operating system's C
438 library. The collation and character classification behavior is
439 controlled by the settings <literal>LC_COLLATE</literal> and
440 <literal>LC_CTYPE</literal>, so they cannot be set independently.
441 </para>
442 <note>
443 <para>
444 The same locale name may have different behavior on different
445 platforms when using the libc provider.
446 </para>
447 </note>
448 </listitem>
449 </varlistentry>
450 </variablelist>
451 </sect2>
452
453 <sect2 id="icu-locales">
454 <title>ICU Locales</title>
455
456 <sect3 id="icu-locale-names">
457 <title>ICU Locale Names</title>
458
459 <para>
460 The ICU format for the locale name is a <link
461 linkend="icu-language-tag">Language Tag</link>.
462
463 <programlisting>
464 CREATE COLLATION mycollation1 (provider = icu, locale = 'ja-JP');
465 CREATE COLLATION mycollation2 (provider = icu, locale = 'fr');
466 </programlisting>
467 </para>
468 </sect3>
469
470 <sect3 id="icu-canonicalization">
471 <title>Locale Canonicalization and Validation</title>
472 <para>
473 When defining a new ICU collation object or database with ICU as the
474 provider, the given locale name is transformed ("canonicalized") into a
475 language tag if not already in that form. For instance,
476
477 <screen>
478 CREATE COLLATION mycollation3 (provider = icu, locale = 'en-US-u-kn-true');
479 NOTICE: using standard form "en-US-u-kn" for locale "en-US-u-kn-true"
480 CREATE COLLATION mycollation4 (provider = icu, locale = 'de_DE.utf8');
481 NOTICE: using standard form "de-DE" for locale "de_DE.utf8"
482 </screen>
483
484 If you see this notice, ensure that the <symbol>provider</symbol> and
485 <symbol>locale</symbol> are the expected result. For consistent results
486 when using the ICU provider, specify the canonical <link
487 linkend="icu-language-tag">language tag</link> instead of relying on the
488 transformation.
489 </para>
490
491 <para>
492 A locale with no language name, or the special language name
493 <literal>root</literal>, is transformed to have the language
494 <literal>und</literal> ("undefined").
495 </para>
496
497 <para>
498 ICU can transform most libc locale names, as well as some other formats,
499 into language tags for easier transition to ICU. If a libc locale name is
500 used in ICU, it may not have precisely the same behavior as in libc.
501 </para>
502
503 <para>
504 If there is a problem interpreting the locale name, or if the locale name
505 represents a language or region that ICU does not recognize, you will see
506 the following warning:
507
508 <screen>
509 CREATE COLLATION nonsense (provider = icu, locale = 'nonsense');
510 WARNING: ICU locale "nonsense" has unknown language "nonsense"
511 HINT: To disable ICU locale validation, set parameter icu_validation_level to DISABLED.
512 CREATE COLLATION
513 </screen>
514
515 <xref linkend="guc-icu-validation-level"/> controls how the message is
516 reported. Unless set to <literal>ERROR</literal>, the collation will
517 still be created, but the behavior may not be what the user intended.
518 </para>
519 </sect3>
520
521 <sect3 id="icu-language-tag">
522 <title>Language Tag</title>
523
524 <para>
525 A language tag, defined in BCP 47, is a standardized identifier used to
526 identify languages, regions, and other information about a locale.
527 </para>
528
529 <para>
530 Basic language tags are simply
531 <replaceable>language</replaceable><literal>-</literal><replaceable>region</replaceable>;
532 or even just <replaceable>language</replaceable>. The
533 <replaceable>language</replaceable> is a language code
534 (e.g. <literal>fr</literal> for French), and
535 <replaceable>region</replaceable> is a region code
536 (e.g. <literal>CA</literal> for Canada). Examples:
537 <literal>ja-JP</literal>, <literal>de</literal>, or
538 <literal>fr-CA</literal>.
539 </para>
540
541 <para>
542 Collation settings may be included in the language tag to customize
543 collation behavior. ICU allows extensive customization, such as
544 sensitivity (or insensitivity) to accents, case, and punctuation;
545 treatment of digits within text; and many other options to satisfy a
546 variety of uses.
547 </para>
548
549 <para>
550 To include this additional collation information in a language tag,
551 append <literal>-u</literal>, which indicates there are additional
552 collation settings, followed by one or more
553 <literal>-</literal><replaceable>key</replaceable><literal>-</literal><replaceable>value</replaceable>
554 pairs. The <replaceable>key</replaceable> is the key for a <link
555 linkend="icu-collation-settings">collation setting</link> and
556 <replaceable>value</replaceable> is a valid value for that setting. For
557 boolean settings, the <literal>-</literal><replaceable>key</replaceable>
558 may be specified without a corresponding
559 <literal>-</literal><replaceable>value</replaceable>, which implies a
560 value of <literal>true</literal>.
561 </para>
562
563 <para>
564 For example, the language tag <literal>en-US-u-kn-ks-level2</literal>
565 means the locale with the English language in the US region, with
566 collation settings <literal>kn</literal> set to <literal>true</literal>
567 and <literal>ks</literal> set to <literal>level2</literal>. Those
568 settings mean the collation will be case-insensitive and treat a sequence
569 of digits as a single number:
570
571 <screen>
572 CREATE COLLATION mycollation5 (provider = icu, deterministic = false, locale = 'en-US-u-kn-ks-level2');
573 SELECT 'aB' = 'Ab' COLLATE mycollation5 as result;
574 result
575 --------
576 t
577 (1 row)
578
579 SELECT 'N-45' &lt; 'N-123' COLLATE mycollation5 as result;
580 result
581 --------
582 t
583 (1 row)
584 </screen>
585 </para>
586
587 <para>
588 See <xref linkend="icu-custom-collations"/> for details and additional
589 examples of using language tags with custom collation information for the
590 locale.
591 </para>
592 </sect3>
593 </sect2>
594
595 <sect2 id="locale-problems">
596 <title>Problems</title>
597
598 <para>
599 If locale support doesn't work according to the explanation above,
600 check that the locale support in your operating system is
601 correctly configured. To check what locales are installed on your
602 system, you can use the command <literal>locale -a</literal> if
603 your operating system provides it.
604 </para>
605
606 <para>
607 Check that <productname>PostgreSQL</productname> is actually using the locale
608 that you think it is. The <envar>LC_COLLATE</envar> and <envar>LC_CTYPE</envar>
609 settings are determined when a database is created, and cannot be
610 changed except by creating a new database. Other locale
611 settings including <envar>LC_MESSAGES</envar> and <envar>LC_MONETARY</envar>
612 are initially determined by the environment the server is started
613 in, but can be changed on-the-fly. You can check the active locale
614 settings using the <command>SHOW</command> command.
615 </para>
616
617 <para>
618 The directory <filename>src/test/locale</filename> in the source
619 distribution contains a test suite for
620 <productname>PostgreSQL</productname>'s locale support.
621 </para>
622
623 <para>
624 Client applications that handle server-side errors by parsing the
625 text of the error message will obviously have problems when the
626 server's messages are in a different language. Authors of such
627 applications are advised to make use of the error code scheme
628 instead.
629 </para>
630
631 <para>
632 Maintaining catalogs of message translations requires the on-going
633 efforts of many volunteers that want to see
634 <productname>PostgreSQL</productname> speak their preferred language well.
635 If messages in your language are currently not available or not fully
636 translated, your assistance would be appreciated. If you want to
637 help, refer to <xref linkend="nls"/> or write to the developers'
638 mailing list.
639 </para>
640 </sect2>
641 </sect1>
642
643
644 <sect1 id="collation">
645 <title>Collation Support</title>
646
647 <indexterm zone="collation"><primary>collation</primary></indexterm>
648
649 <para>
650 The collation feature allows specifying the sort order and character
651 classification behavior of data per-column, or even per-operation.
652 This alleviates the restriction that the
653 <symbol>LC_COLLATE</symbol> and <symbol>LC_CTYPE</symbol> settings
654 of a database cannot be changed after its creation.
655 </para>
656
657 <sect2 id="collation-concepts">
658 <title>Concepts</title>
659
660 <para>
661 Conceptually, every expression of a collatable data type has a
662 collation. (The built-in collatable data types are
663 <type>text</type>, <type>varchar</type>, and <type>char</type>.
664 User-defined base types can also be marked collatable, and of course
665 a <glossterm linkend="glossary-domain">domain</glossterm> over a
666 collatable data type is collatable.) If the
667 expression is a column reference, the collation of the expression is the
668 defined collation of the column. If the expression is a constant, the
669 collation is the default collation of the data type of the
670 constant. The collation of a more complex expression is derived
671 from the collations of its inputs, as described below.
672 </para>
673
674 <para>
675 The collation of an expression can be the <quote>default</quote>
676 collation, which means the locale settings defined for the
677 database. It is also possible for an expression's collation to be
678 indeterminate. In such cases, ordering operations and other
679 operations that need to know the collation will fail.
680 </para>
681
682 <para>
683 When the database system has to perform an ordering or a character
684 classification, it uses the collation of the input expression. This
685 happens, for example, with <literal>ORDER BY</literal> clauses
686 and function or operator calls such as <literal>&lt;</literal>.
687 The collation to apply for an <literal>ORDER BY</literal> clause
688 is simply the collation of the sort key. The collation to apply for a
689 function or operator call is derived from the arguments, as described
690 below. In addition to comparison operators, collations are taken into
691 account by functions that convert between lower and upper case
692 letters, such as <function>lower</function>, <function>upper</function>, and
693 <function>initcap</function>; by pattern matching operators; and by
694 <function>to_char</function> and related functions.
695 </para>
696
697 <para>
698 For a function or operator call, the collation that is derived by
699 examining the argument collations is used at run time for performing
700 the specified operation. If the result of the function or operator
701 call is of a collatable data type, the collation is also used at parse
702 time as the defined collation of the function or operator expression,
703 in case there is a surrounding expression that requires knowledge of
704 its collation.
705 </para>
706
707 <para>
708 The <firstterm>collation derivation</firstterm> of an expression can be
709 implicit or explicit. This distinction affects how collations are
710 combined when multiple different collations appear in an
711 expression. An explicit collation derivation occurs when a
712 <literal>COLLATE</literal> clause is used; all other collation
713 derivations are implicit. When multiple collations need to be
714 combined, for example in a function call, the following rules are
715 used:
716
717 <orderedlist>
718 <listitem>
719 <para>
720 If any input expression has an explicit collation derivation, then
721 all explicitly derived collations among the input expressions must be
722 the same, otherwise an error is raised. If any explicitly
723 derived collation is present, that is the result of the
724 collation combination.
725 </para>
726 </listitem>
727
728 <listitem>
729 <para>
730 Otherwise, all input expressions must have the same implicit
731 collation derivation or the default collation. If any non-default
732 collation is present, that is the result of the collation combination.
733 Otherwise, the result is the default collation.
734 </para>
735 </listitem>
736
737 <listitem>
738 <para>
739 If there are conflicting non-default implicit collations among the
740 input expressions, then the combination is deemed to have indeterminate
741 collation. This is not an error condition unless the particular
742 function being invoked requires knowledge of the collation it should
743 apply. If it does, an error will be raised at run-time.
744 </para>
745 </listitem>
746 </orderedlist>
747
748 For example, consider this table definition:
749 <programlisting>
750 CREATE TABLE test1 (
751 a text COLLATE "de_DE",
752 b text COLLATE "es_ES",
753 ...
754 );
755 </programlisting>
756
757 Then in
758 <programlisting>
759 SELECT a &lt; 'foo' FROM test1;
760 </programlisting>
761 the <literal>&lt;</literal> comparison is performed according to
762 <literal>de_DE</literal> rules, because the expression combines an
763 implicitly derived collation with the default collation. But in
764 <programlisting>
765 SELECT a &lt; ('foo' COLLATE "fr_FR") FROM test1;
766 </programlisting>
767 the comparison is performed using <literal>fr_FR</literal> rules,
768 because the explicit collation derivation overrides the implicit one.
769 Furthermore, given
770 <programlisting>
771 SELECT a &lt; b FROM test1;
772 </programlisting>
773 the parser cannot determine which collation to apply, since the
774 <structfield>a</structfield> and <structfield>b</structfield> columns have conflicting
775 implicit collations. Since the <literal>&lt;</literal> operator
776 does need to know which collation to use, this will result in an
777 error. The error can be resolved by attaching an explicit collation
778 specifier to either input expression, thus:
779 <programlisting>
780 SELECT a &lt; b COLLATE "de_DE" FROM test1;
781 </programlisting>
782 or equivalently
783 <programlisting>
784 SELECT a COLLATE "de_DE" &lt; b FROM test1;
785 </programlisting>
786 On the other hand, the structurally similar case
787 <programlisting>
788 SELECT a || b FROM test1;
789 </programlisting>
790 does not result in an error, because the <literal>||</literal> operator
791 does not care about collations: its result is the same regardless
792 of the collation.
793 </para>
794
795 <para>
796 The collation assigned to a function or operator's combined input
797 expressions is also considered to apply to the function or operator's
798 result, if the function or operator delivers a result of a collatable
799 data type. So, in
800 <programlisting>
801 SELECT * FROM test1 ORDER BY a || 'foo';
802 </programlisting>
803 the ordering will be done according to <literal>de_DE</literal> rules.
804 But this query:
805 <programlisting>
806 SELECT * FROM test1 ORDER BY a || b;
807 </programlisting>
808 results in an error, because even though the <literal>||</literal> operator
809 doesn't need to know a collation, the <literal>ORDER BY</literal> clause does.
810 As before, the conflict can be resolved with an explicit collation
811 specifier:
812 <programlisting>
813 SELECT * FROM test1 ORDER BY a || b COLLATE "fr_FR";
814 </programlisting>
815 </para>
816 </sect2>
817
818 <sect2 id="collation-managing">
819 <title>Managing Collations</title>
820
821 <para>
822 A collation is an SQL schema object that maps an SQL name to locales
823 provided by libraries installed in the operating system. A collation
824 definition has a <firstterm>provider</firstterm> that specifies which
825 library supplies the locale data. One standard provider name
826 is <literal>libc</literal>, which uses the locales provided by the
827 operating system C library. These are the locales used by most tools
828 provided by the operating system. Another provider
829 is <literal>icu</literal>, which uses the external
830 ICU<indexterm><primary>ICU</primary></indexterm> library. ICU locales can only be
831 used if support for ICU was configured when PostgreSQL was built.
832 </para>
833
834 <para>
835 A collation object provided by <literal>libc</literal> maps to a
836 combination of <symbol>LC_COLLATE</symbol> and <symbol>LC_CTYPE</symbol>
837 settings, as accepted by the <literal>setlocale()</literal> system library call. (As
838 the name would suggest, the main purpose of a collation is to set
839 <symbol>LC_COLLATE</symbol>, which controls the sort order. But
840 it is rarely necessary in practice to have an
841 <symbol>LC_CTYPE</symbol> setting that is different from
842 <symbol>LC_COLLATE</symbol>, so it is more convenient to collect
843 these under one concept than to create another infrastructure for
844 setting <symbol>LC_CTYPE</symbol> per expression.) Also,
845 a <literal>libc</literal> collation
846 is tied to a character set encoding (see <xref linkend="multibyte"/>).
847 The same collation name may exist for different encodings.
848 </para>
849
850 <para>
851 A collation object provided by <literal>icu</literal> maps to a named
852 collator provided by the ICU library. ICU does not support
853 separate <quote>collate</quote> and <quote>ctype</quote> settings, so
854 they are always the same. Also, ICU collations are independent of the
855 encoding, so there is always only one ICU collation of a given name in
856 a database.
857 </para>
858
859 <sect3 id="collation-managing-standard">
860 <title>Standard Collations</title>
861
862 <para>
863 On all platforms, the following collations are supported:
864
865 <variablelist>
866 <varlistentry>
867 <term><literal>unicode</literal></term>
868 <listitem>
869 <para>
870 This SQL standard collation sorts using the Unicode Collation
871 Algorithm with the Default Unicode Collation Element Table. It is
872 available in all encodings. ICU support is required to use this
873 collation, and behavior may change if <productname>PostgreSQL</productname> is built with a
874 different version of ICU. (This collation has the same behavior as
875 the ICU root locale; see <xref
876 linkend="collation-managing-predefined-icu-und-x-icu"/>.)
877 </para>
878 </listitem>
879 </varlistentry>
880
881 <varlistentry>
882 <term><literal>ucs_basic</literal></term>
883 <listitem>
884 <para>
885 This SQL standard collation sorts using the Unicode code point values
886 rather than natural language order, and only the ASCII letters
887 <quote><literal>A</literal></quote> through
888 <quote><literal>Z</literal></quote> are treated as letters. The
889 behavior is efficient and stable across all versions. Only available
890 for encoding <literal>UTF8</literal>. (This collation has the same
891 behavior as the libc locale specification <literal>C</literal> in
892 <literal>UTF8</literal> encoding.)
893 </para>
894 </listitem>
895 </varlistentry>
896
897 <varlistentry>
898 <term><literal>pg_unicode_fast</literal></term>
899 <listitem>
900 <para>
901 This collation sorts by Unicode code point values rather than natural
902 language order. For the functions <function>lower</function>,
903 <function>initcap</function>, and <function>upper</function> it uses
904 Unicode full case mapping. For pattern matching (including regular
905 expressions), it uses the Standard variant of Unicode <ulink
906 url="https://www.unicode.org/reports/tr18/#Compatibility_Properties">Compatibility
907 Properties</ulink>. Behavior is efficient and stable within a
908 <productname>Postgres</productname> major version. It is only
909 available for encoding <literal>UTF8</literal>.
910 </para>
911 </listitem>
912 </varlistentry>
913
914 <varlistentry>
915 <term><literal>pg_c_utf8</literal></term>
916 <listitem>
917 <para>
918 This collation sorts by Unicode code point values rather than natural
919 language order. For the functions <function>lower</function>,
920 <function>initcap</function>, and <function>upper</function>, it uses
921 Unicode simple case mapping. For pattern matching (including regular
922 expressions), it uses the POSIX Compatible variant of Unicode <ulink
923 url="https://www.unicode.org/reports/tr18/#Compatibility_Properties">Compatibility
924 Properties</ulink>. Behavior is efficient and stable within a
925 <productname>PostgreSQL</productname> major version. This collation is
926 only available for encoding <literal>UTF8</literal>.
927 </para>
928 </listitem>
929 </varlistentry>
930
931 <varlistentry>
932 <term><literal>C</literal> (equivalent to <literal>POSIX</literal>)</term>
933 <listitem>
934 <para>
935 The <literal>C</literal> and <literal>POSIX</literal> collations are
936 based on <quote>traditional C</quote> behavior. They sort by byte
937 values rather than natural language order, and only the ASCII letters
938 <quote><literal>A</literal></quote> through
939 <quote><literal>Z</literal></quote> are treated as letters. The
940 behavior is efficient and stable across all versions for a given
941 database encoding, but behavior may vary between different database
942 encodings.
943 </para>
944 </listitem>
945 </varlistentry>
946
947 <varlistentry>
948 <term><literal>default</literal></term>
949 <listitem>
950 <para>
951 The <literal>default</literal> collation selects the locale specified
952 at database creation time.
953 </para>
954 </listitem>
955 </varlistentry>
956 </variablelist>
957 </para>
958
959 <para>
960 Additional collations may be available depending on operating system
961 support. The efficiency and stability of these additional collations
962 depend on the collation provider, the provider version, and the locale.
963 </para>
964 </sect3>
965
966 <sect3 id="collation-managing-predefined">
967 <title>Predefined Collations</title>
968
969 <para>
970 If the operating system provides support for using multiple locales
971 within a single program (<function>newlocale</function> and related functions),
972 or if support for ICU is configured,
973 then when a database cluster is initialized, <command>initdb</command>
974 populates the system catalog <literal>pg_collation</literal> with
975 collations based on all the locales it finds in the operating
976 system at the time.
977 </para>
978
979 <para>
980 To inspect the currently available locales, use the query <literal>SELECT
981 * FROM pg_collation</literal>, or the command <command>\dOS+</command>
982 in <application>psql</application>.
983 </para>
984
985 <sect4 id="collation-managing-predefined-libc">
986 <title>libc Collations</title>
987
988 <para>
989 For example, the operating system might
990 provide a locale named <literal>de_DE.utf8</literal>.
991 <command>initdb</command> would then create a collation named
992 <literal>de_DE.utf8</literal> for encoding <literal>UTF8</literal>
993 that has both <symbol>LC_COLLATE</symbol> and
994 <symbol>LC_CTYPE</symbol> set to <literal>de_DE.utf8</literal>.
995 It will also create a collation with the <literal>.utf8</literal>
996 tag stripped off the name. So you could also use the collation
997 under the name <literal>de_DE</literal>, which is less cumbersome
998 to write and makes the name less encoding-dependent. Note that,
999 nevertheless, the initial set of collation names is
1000 platform-dependent.
1001 </para>
1002
1003 <para>
1004 The default set of collations provided by <literal>libc</literal> map
1005 directly to the locales installed in the operating system, which can be
1006 listed using the command <literal>locale -a</literal>. In case
1007 a <literal>libc</literal> collation is needed that has different values
1008 for <symbol>LC_COLLATE</symbol> and <symbol>LC_CTYPE</symbol>, or if new
1009 locales are installed in the operating system after the database system
1010 was initialized, then a new collation may be created using
1011 the <xref linkend="sql-createcollation"/> command.
1012 New operating system locales can also be imported en masse using
1013 the <link linkend="functions-admin-collation"><function>pg_import_system_collations()</function></link> function.
1014 </para>
1015
1016 <para>
1017 Within any particular database, only collations that use that
1018 database's encoding are of interest. Other entries in
1019 <literal>pg_collation</literal> are ignored. Thus, a stripped collation
1020 name such as <literal>de_DE</literal> can be considered unique
1021 within a given database even though it would not be unique globally.
1022 Use of the stripped collation names is recommended, since it will
1023 make one fewer thing you need to change if you decide to change to
1024 another database encoding. Note however that the <literal>default</literal>,
1025 <literal>C</literal>, and <literal>POSIX</literal> collations can be used regardless of
1026 the database encoding.
1027 </para>
1028
1029 <para>
1030 <productname>PostgreSQL</productname> considers distinct collation
1031 objects to be incompatible even when they have identical properties.
1032 Thus for example,
1033 <programlisting>
1034 SELECT a COLLATE "C" &lt; b COLLATE "POSIX" FROM test1;
1035 </programlisting>
1036 will draw an error even though the <literal>C</literal> and <literal>POSIX</literal>
1037 collations have identical behaviors. Mixing stripped and non-stripped
1038 collation names is therefore not recommended.
1039 </para>
1040 </sect4>
1041
1042 <sect4 id="collation-managing-predefined-icu">
1043 <title>ICU Collations</title>
1044
1045 <para>
1046 With ICU, it is not sensible to enumerate all possible locale names. ICU
1047 uses a particular naming system for locales, but there are many more ways
1048 to name a locale than there are actually distinct locales.
1049 <command>initdb</command> uses the ICU APIs to extract a set of distinct
1050 locales to populate the initial set of collations. Collations provided by
1051 ICU are created in the SQL environment with names in BCP 47 language tag
1052 format, with a <quote>private use</quote>
1053 extension <literal>-x-icu</literal> appended, to distinguish them from
1054 libc locales.
1055 </para>
1056
1057 <para>
1058 Here are some example collations that might be created:
1059
1060 <variablelist>
1061 <varlistentry id="collation-managing-predefined-icu-de-x-icu">
1062 <term><literal>de-x-icu</literal></term>
1063 <listitem>
1064 <para>German collation, default variant</para>
1065 </listitem>
1066 </varlistentry>
1067
1068 <varlistentry id="collation-managing-predefined-icu-de-at-x-icu">
1069 <term><literal>de-AT-x-icu</literal></term>
1070 <listitem>
1071 <para>German collation for Austria, default variant</para>
1072 <para>
1073 (There are also, say, <literal>de-DE-x-icu</literal>
1074 or <literal>de-CH-x-icu</literal>, but as of this writing, they are
1075 equivalent to <literal>de-x-icu</literal>.)
1076 </para>
1077 </listitem>
1078 </varlistentry>
1079
1080 <varlistentry id="collation-managing-predefined-icu-und-x-icu">
1081 <term><literal>und-x-icu</literal> (for <quote>undefined</quote>)</term>
1082 <listitem>
1083 <para>
1084 ICU <quote>root</quote> collation. Use this to get a reasonable
1085 language-agnostic sort order.
1086 </para>
1087 </listitem>
1088 </varlistentry>
1089 </variablelist>
1090 </para>
1091
1092 <para>
1093 Some (less frequently used) encodings are not supported by ICU. When the
1094 database encoding is one of these, ICU collation entries
1095 in <literal>pg_collation</literal> are ignored. Attempting to use one
1096 will draw an error along the lines of <quote>collation "de-x-icu" for
1097 encoding "WIN874" does not exist</quote>.
1098 </para>
1099 </sect4>
1100 </sect3>
1101
1102 <sect3 id="collation-create">
1103 <title>Creating New Collation Objects</title>
1104
1105 <para>
1106 If the standard and predefined collations are not sufficient, users can
1107 create their own collation objects using the SQL
1108 command <xref linkend="sql-createcollation"/>.
1109 </para>
1110
1111 <para>
1112 The standard and predefined collations are in the
1113 schema <literal>pg_catalog</literal>, like all predefined objects.
1114 User-defined collations should be created in user schemas. This also
1115 ensures that they are saved by <command>pg_dump</command>.
1116 </para>
1117
1118 <sect4 id="collation-managing-create-libc">
1119 <title>libc Collations</title>
1120
1121 <para>
1122 New libc collations can be created like this:
1123 <programlisting>
1124 CREATE COLLATION german (provider = libc, locale = 'de_DE');
1125 </programlisting>
1126 The exact values that are acceptable for the <literal>locale</literal>
1127 clause in this command depend on the operating system. On Unix-like
1128 systems, the command <literal>locale -a</literal> will show a list.
1129 </para>
1130
1131 <para>
1132 Since the predefined libc collations already include all collations
1133 defined in the operating system when the database instance is
1134 initialized, it is not often necessary to manually create new ones.
1135 Reasons might be if a different naming system is desired (in which case
1136 see also <xref linkend="collation-copy"/>) or if the operating system has
1137 been upgraded to provide new locale definitions (in which case see
1138 also <link linkend="functions-admin-collation"><function>pg_import_system_collations()</function></link>).
1139 </para>
1140 </sect4>
1141
1142 <sect4 id="collation-managing-create-icu">
1143 <title>ICU Collations</title>
1144
1145 <para>
1146 ICU collations can be created like:
1147
1148 <programlisting>
1149 CREATE COLLATION german (provider = icu, locale = 'de-DE');
1150 </programlisting>
1151
1152 ICU locales are specified as a BCP 47 <link
1153 linkend="icu-language-tag">Language Tag</link>, but can also accept most
1154 libc-style locale names. If possible, libc-style locale names are
1155 transformed into language tags.
1156 </para>
1157 <para>
1158 New ICU collations can customize collation behavior extensively by
1159 including collation attributes in the language tag. See <xref
1160 linkend="icu-custom-collations"/> for details and examples.
1161 </para>
1162 </sect4>
1163 <sect4 id="collation-copy">
1164 <title>Copying Collations</title>
1165
1166 <para>
1167 The command <xref linkend="sql-createcollation"/> can also be used to
1168 create a new collation from an existing collation, which can be useful to
1169 be able to use operating-system-independent collation names in
1170 applications, create compatibility names, or use an ICU-provided collation
1171 under a more readable name. For example:
1172 <programlisting>
1173 CREATE COLLATION german FROM "de_DE";
1174 CREATE COLLATION french FROM "fr-x-icu";
1175 </programlisting>
1176 </para>
1177 </sect4>
1178 </sect3>
1179
1180 <sect3 id="collation-nondeterministic">
1181 <title>Nondeterministic Collations</title>
1182
1183 <para>
1184 A collation is either <firstterm>deterministic</firstterm> or
1185 <firstterm>nondeterministic</firstterm>. A deterministic collation uses
1186 deterministic comparisons, which means that it considers strings to be
1187 equal only if they consist of the same byte sequence. Nondeterministic
1188 comparison may determine strings to be equal even if they consist of
1189 different bytes. Typical situations include case-insensitive comparison,
1190 accent-insensitive comparison, as well as comparison of strings in
1191 different Unicode normal forms. It is up to the collation provider to
1192 actually implement such insensitive comparisons; the deterministic flag
1193 only determines whether ties are to be broken using bytewise comparison.
1194 See also <ulink url="https://www.unicode.org/reports/tr10">Unicode Technical
1195 Standard 10</ulink> for more information on the terminology.
1196 </para>
1197
1198 <para>
1199 To create a nondeterministic collation, specify the property
1200 <literal>deterministic = false</literal> to <command>CREATE
1201 COLLATION</command>, for example:
1202 <programlisting>
1203 CREATE COLLATION ndcoll (provider = icu, locale = 'und', deterministic = false);
1204 </programlisting>
1205 This example would use the standard Unicode collation in a
1206 nondeterministic way. In particular, this would allow strings in
1207 different normal forms to be compared correctly. More interesting
1208 examples make use of the ICU customization facilities explained above.
1209 For example:
1210 <programlisting>
1211 CREATE COLLATION case_insensitive (provider = icu, locale = 'und-u-ks-level2', deterministic = false);
1212 CREATE COLLATION ignore_accents (provider = icu, locale = 'und-u-ks-level1-kc-true', deterministic = false);
1213 </programlisting>
1214 </para>
1215
1216 <para>
1217 All standard and predefined collations are deterministic, all
1218 user-defined collations are deterministic by default. While
1219 nondeterministic collations give a more <quote>correct</quote> behavior,
1220 especially when considering the full power of Unicode and its many
1221 special cases, they also have some drawbacks. Foremost, their use leads
1222 to a performance penalty. Note, in particular, that B-tree cannot use
1223 deduplication with indexes that use a nondeterministic collation. Also,
1224 certain operations are not possible with nondeterministic collations,
1225 such as some pattern matching operations. Therefore, they should be used
1226 only in cases where they are specifically wanted.
1227 </para>
1228
1229 <tip>
1230 <para>
1231 To deal with text in different Unicode normalization forms, it is also
1232 an option to use the functions/expressions
1233 <function>normalize</function> and <literal>is normalized</literal> to
1234 preprocess or check the strings, instead of using nondeterministic
1235 collations. There are different trade-offs for each approach.
1236 </para>
1237 </tip>
1238 </sect3>
1239 </sect2>
1240
1241 <sect2 id="icu-custom-collations">
1242 <title>ICU Custom Collations</title>
1243
1244 <para>
1245 ICU allows extensive control over collation behavior by defining new
1246 collations with collation settings as a part of the language tag. These
1247 settings can modify the collation order to suit a variety of needs. For
1248 instance:
1249
1250 <programlisting>
1251 -- ignore differences in accents and case
1252 CREATE COLLATION ignore_accent_case (provider = icu, deterministic = false, locale = 'und-u-ks-level1');
1253 SELECT 'Ã…' = 'A' COLLATE ignore_accent_case; -- true
1254 SELECT 'z' = 'Z' COLLATE ignore_accent_case; -- true
1255
1256 -- upper case letters sort before lower case.
1257 CREATE COLLATION upper_first (provider = icu, locale = 'und-u-kf-upper');
1258 SELECT 'B' &lt; 'b' COLLATE upper_first; -- true
1259
1260 -- treat digits numerically and ignore punctuation
1261 CREATE COLLATION num_ignore_punct (provider = icu, deterministic = false, locale = 'und-u-ka-shifted-kn');
1262 SELECT 'id-45' &lt; 'id-123' COLLATE num_ignore_punct; -- true
1263 SELECT 'w;x*y-z' = 'wxyz' COLLATE num_ignore_punct; -- true
1264 </programlisting>
1265
1266 Many of the available options are described in <xref
1267 linkend="icu-collation-settings"/>, or see <xref
1268 linkend="icu-external-references"/> for more details.
1269 </para>
1270
1271 <sect3 id="icu-collation-comparison-levels">
1272 <title>ICU Comparison Levels</title>
1273
1274 <para>
1275 Comparison of two strings (collation) in ICU is determined by a
1276 multi-level process, where textual features are grouped into
1277 "levels". Treatment of each level is controlled by the <link
1278 linkend="icu-collation-settings-table">collation settings</link>. Higher
1279 levels correspond to finer textual features.
1280 </para>
1281
1282 <para>
1283 <xref linkend="icu-collation-levels"/> shows which textual feature
1284 differences are considered significant when determining equality at the
1285 given level. The Unicode character <literal>U+2063</literal> is an
1286 invisible separator, and as seen in the table, is ignored for at all
1287 levels of comparison less than <literal>identic</literal>.
1288 </para>
1289
1290 <table id="icu-collation-levels">
1291 <title>ICU Collation Levels</title>
1292 <tgroup cols="8">
1293 <colspec colname="col1" colwidth="1*"/>
1294 <colspec colname="col2" colwidth="1.25*"/>
1295 <colspec colname="col3" colwidth="1*"/>
1296 <colspec colname="col4" colwidth="1*"/>
1297 <colspec colname="col5" colwidth="1*"/>
1298 <colspec colname="col6" colwidth="1*"/>
1299 <colspec colname="col7" colwidth="1*"/>
1300 <colspec colname="col8" colwidth="1*"/>
1301
1302 <thead>
1303 <row>
1304 <entry>Level</entry>
1305 <entry>Description</entry>
1306 <entry><literal>'f' = 'f'</literal></entry>
1307 <entry><literal>'ab' = U&amp;'a\2063b'</literal></entry>
1308 <entry><literal>'x-y' = 'x_y'</literal></entry>
1309 <entry><literal>'g' = 'G'</literal></entry>
1310 <entry><literal>'n' = 'ñ'</literal></entry>
1311 <entry><literal>'y' = 'z'</literal></entry>
1312 </row>
1313 </thead>
1314
1315 <tbody>
1316 <row>
1317 <entry>level1</entry>
1318 <entry>Base Character</entry>
1319 <entry><literal>true</literal></entry>
1320 <entry><literal>true</literal></entry>
1321 <entry><literal>true</literal></entry>
1322 <entry><literal>true</literal></entry>
1323 <entry><literal>true</literal></entry>
1324 <entry><literal>false</literal></entry>
1325 </row>
1326 <row>
1327 <entry>level2</entry>
1328 <entry>Accents</entry>
1329 <entry><literal>true</literal></entry>
1330 <entry><literal>true</literal></entry>
1331 <entry><literal>true</literal></entry>
1332 <entry><literal>true</literal></entry>
1333 <entry><literal>false</literal></entry>
1334 <entry><literal>false</literal></entry>
1335 </row>
1336 <row>
1337 <entry>level3</entry>
1338 <entry>Case/Variants</entry>
1339 <entry><literal>true</literal></entry>
1340 <entry><literal>true</literal></entry>
1341 <entry><literal>true</literal></entry>
1342 <entry><literal>false</literal></entry>
1343 <entry><literal>false</literal></entry>
1344 <entry><literal>false</literal></entry>
1345 </row>
1346 <row>
1347 <entry>level4</entry>
1348 <entry>Punctuation<footnote><para>only with
1349 <literal>ka-shifted</literal>; see <xref
1350 linkend="icu-collation-settings-table"/></para></footnote></entry>
1351 <entry><literal>true</literal></entry>
1352 <entry><literal>true</literal></entry>
1353 <entry><literal>false</literal></entry>
1354 <entry><literal>false</literal></entry>
1355 <entry><literal>false</literal></entry>
1356 <entry><literal>false</literal></entry>
1357 </row>
1358 <row>
1359 <entry>identic</entry>
1360 <entry>All</entry>
1361 <entry><literal>true</literal></entry>
1362 <entry><literal>false</literal></entry>
1363 <entry><literal>false</literal></entry>
1364 <entry><literal>false</literal></entry>
1365 <entry><literal>false</literal></entry>
1366 <entry><literal>false</literal></entry>
1367 </row>
1368 </tbody>
1369 </tgroup>
1370 </table>
1371
1372 <para>
1373 At every level, even with full normalization off, basic normalization is
1374 performed. For example, <literal>'á'</literal> may be composed of the
1375 code points <literal>U&amp;'\0061\0301'</literal> or the single code
1376 point <literal>U&amp;'\00E1'</literal>, and those sequences will be
1377 considered equal even at the <literal>identic</literal> level. To treat
1378 any difference in code point representation as distinct, use a collation
1379 created with <symbol>deterministic</symbol> set to
1380 <literal>true</literal>.
1381 </para>
1382
1383 <sect4 id="icu-collation-level-examples">
1384 <title>Collation Level Examples</title>
1385
1386 <programlisting>
1387 CREATE COLLATION level3 (provider = icu, deterministic = false, locale = 'und-u-ka-shifted-ks-level3');
1388 CREATE COLLATION level4 (provider = icu, deterministic = false, locale = 'und-u-ka-shifted-ks-level4');
1389 CREATE COLLATION identic (provider = icu, deterministic = false, locale = 'und-u-ka-shifted-ks-identic');
1390
1391 -- invisible separator ignored at all levels except identic
1392 SELECT 'ab' = U&amp;'a\2063b' COLLATE level4; -- true
1393 SELECT 'ab' = U&amp;'a\2063b' COLLATE identic; -- false
1394
1395 -- punctuation ignored at level3 but not at level 4
1396 SELECT 'x-y' = 'x_y' COLLATE level3; -- true
1397 SELECT 'x-y' = 'x_y' COLLATE level4; -- false
1398 </programlisting>
1399
1400 </sect4>
1401 </sect3>
1402
1403 <sect3 id="icu-collation-settings">
1404 <title>Collation Settings for an ICU Locale</title>
1405
1406 <para>
1407 <xref linkend="icu-collation-settings-table"/> shows the available
1408 collation settings, which can be used as part of a language tag to
1409 customize a collation.
1410 </para>
1411
1412 <table id="icu-collation-settings-table">
1413 <title>ICU Collation Settings</title>
1414 <tgroup cols="4">
1415 <colspec colname="col1" colwidth="1*"/>
1416 <colspec colname="col2" colwidth="2*"/>
1417 <colspec colname="col3" colwidth="2*"/>
1418 <colspec colname="col4" colwidth="5*"/>
1419
1420 <thead>
1421 <row>
1422 <entry>Key</entry>
1423 <entry>Values</entry>
1424 <entry>Default</entry>
1425 <entry>Description</entry>
1426 </row>
1427 </thead>
1428
1429 <tbody>
1430 <row>
1431 <entry><literal>co</literal></entry>
1432 <entry><literal>emoji</literal>, <literal>phonebk</literal>, <literal>standard</literal>, <replaceable>...</replaceable></entry>
1433 <entry><literal>standard</literal></entry>
1434 <entry>
1435 Collation type. See <xref linkend="icu-external-references"/> for additional options and details.
1436 </entry>
1437 </row>
1438
1439 <row>
1440 <entry><literal>ka</literal></entry>
1441 <entry><literal>noignore</literal>, <literal>shifted</literal></entry>
1442 <entry><literal>noignore</literal></entry>
1443 <entry>
1444 If set to <literal>shifted</literal>, causes some characters
1445 (e.g. punctuation or space) to be ignored in comparison. Key
1446 <literal>ks</literal> must be set to <literal>level3</literal> or
1447 lower to take effect. Set key <literal>kv</literal> to control which
1448 character classes are ignored.
1449 </entry>
1450 </row>
1451
1452 <row>
1453 <entry><literal>kb</literal></entry>
1454 <entry><literal>true</literal>, <literal>false</literal></entry>
1455 <entry><literal>false</literal></entry>
1456 <entry>
1457 Backwards comparison for the level 2 differences. For example,
1458 locale <literal>und-u-kb</literal> sorts <literal>'àe'</literal>
1459 before <literal>'aé'</literal>.
1460 </entry>
1461 </row>
1462
1463 <row>
1464 <entry><literal>kc</literal></entry>
1465 <entry><literal>true</literal>, <literal>false</literal></entry>
1466 <entry><literal>false</literal></entry>
1467 <entry>
1468 <para>
1469 Separates case into a "level 2.5" that falls between accents and
1470 other level 3 features.
1471 </para>
1472 <para>
1473 If set to <literal>true</literal> and <literal>ks</literal> is set
1474 to <literal>level1</literal>, will ignore accents but take case
1475 into account.
1476 </para>
1477 </entry>
1478 </row>
1479
1480 <row>
1481 <entry><literal>kf</literal></entry>
1482 <entry>
1483 <literal>upper</literal>, <literal>lower</literal>,
1484 <literal>false</literal>
1485 </entry>
1486 <entry><literal>false</literal></entry>
1487 <entry>
1488 If set to <literal>upper</literal>, upper case sorts before lower
1489 case. If set to <literal>lower</literal>, lower case sorts before
1490 upper case. If set to <literal>false</literal>, the sort depends on
1491 the rules of the locale.
1492 </entry>
1493 </row>
1494
1495 <row>
1496 <entry><literal>kn</literal></entry>
1497 <entry><literal>true</literal>, <literal>false</literal></entry>
1498 <entry><literal>false</literal></entry>
1499 <entry>
1500 If set to <literal>true</literal>, numbers within a string are
1501 treated as a single numeric value rather than a sequence of
1502 digits. For example, <literal>'id-45'</literal> sorts before
1503 <literal>'id-123'</literal>.
1504 </entry>
1505 </row>
1506
1507 <row>
1508 <entry><literal>kk</literal></entry>
1509 <entry><literal>true</literal>, <literal>false</literal></entry>
1510 <entry><literal>false</literal></entry>
1511 <entry>
1512 <para>
1513 Enable full normalization; may affect performance. Basic
1514 normalization is performed even when set to
1515 <literal>false</literal>. Locales for languages that require full
1516 normalization typically enable it by default.
1517 </para>
1518 <para>
1519 Full normalization is important in some cases, such as when
1520 multiple accents are applied to a single character. For example,
1521 the code point sequences <literal>U&amp;'\0065\0323\0302'</literal>
1522 and <literal>U&amp;'\0065\0302\0323'</literal> represent
1523 an <literal>e</literal> with circumflex and dot-below accents
1524 applied in different orders. With full normalization
1525 on, these code point sequences are treated as equal; otherwise they
1526 are unequal.
1527 </para>
1528 </entry>
1529 </row>
1530
1531 <row>
1532 <entry><literal>kr</literal></entry>
1533 <entry>
1534 <literal>space</literal>, <literal>punct</literal>,
1535 <literal>symbol</literal>, <literal>currency</literal>,
1536 <literal>digit</literal>, <replaceable>script-id</replaceable>
1537 </entry>
1538 <entry></entry>
1539 <entry>
1540 <para>
1541 Set to one or more of the valid values, or any BCP 47
1542 <replaceable>script-id</replaceable>, e.g. <literal>latn</literal>
1543 ("Latin") or <literal>grek</literal> ("Greek"). Multiple values are
1544 separated by "<literal>-</literal>".
1545 </para>
1546 <para>
1547 Redefines the ordering of classes of characters; those characters
1548 belonging to a class earlier in the list sort before characters
1549 belonging to a class later in the list. For instance, the value
1550 <literal>digit-currency-space</literal> (as part of a language tag
1551 like <literal>und-u-kr-digit-currency-space</literal>) sorts
1552 punctuation before digits and spaces.
1553 </para>
1554 </entry>
1555 </row>
1556
1557 <row>
1558 <entry><literal>ks</literal></entry>
1559 <entry><literal>level1</literal>, <literal>level2</literal>, <literal>level3</literal>, <literal>level4</literal>, <literal>identic</literal></entry>
1560 <entry><literal>level3</literal></entry>
1561 <entry>
1562 Sensitivity (or "strength") when determining equality, with
1563 <literal>level1</literal> the least sensitive to differences and
1564 <literal>identic</literal> the most sensitive to differences. See
1565 <xref linkend="icu-collation-levels"/> for details.
1566 </entry>
1567 </row>
1568
1569 <row>
1570 <entry><literal>kv</literal></entry>
1571 <entry>
1572 <literal>space</literal>, <literal>punct</literal>,
1573 <literal>symbol</literal>, <literal>currency</literal>
1574 </entry>
1575 <entry><literal>punct</literal></entry>
1576 <entry>
1577 Classes of characters ignored during comparison at level 3. Setting
1578 to a later value includes earlier values;
1579 e.g. <literal>symbol</literal> also includes
1580 <literal>punct</literal> and <literal>space</literal> in the
1581 characters to be ignored. Key <literal>ka</literal> must be set to
1582 <literal>shifted</literal> and key <literal>ks</literal> must be set
1583 to <literal>level3</literal> or lower to take effect.
1584 </entry>
1585 </row>
1586 </tbody>
1587 </tgroup>
1588 </table>
1589
1590 <para>
1591 Defaults may depend on locale. The above table is not meant to be
1592 complete. See <xref linkend="icu-external-references"/> for additional
1593 options and details.
1594 </para>
1595
1596 <note>
1597 <para>
1598 For many collation settings, you must create the collation with
1599 <option>deterministic</option> set to <literal>false</literal> for the
1600 setting to have the desired effect (see <xref
1601 linkend="collation-nondeterministic"/>). Additionally, some settings
1602 only take effect when the key <literal>ka</literal> is set to
1603 <literal>shifted</literal> (see <xref
1604 linkend="icu-collation-settings-table"/>).
1605 </para>
1606 </note>
1607 </sect3>
1608
1609 <sect3 id="icu-locale-examples">
1610 <title>Collation Settings Examples</title>
1611
1612 <variablelist>
1613 <varlistentry id="collation-managing-create-icu-de-u-co-phonebk-x-icu">
1614 <term><literal>CREATE COLLATION "de-u-co-phonebk-x-icu" (provider = icu, locale = 'de-u-co-phonebk');</literal></term>
1615 <listitem>
1616 <para>German collation with phone book collation type</para>
1617 </listitem>
1618 </varlistentry>
1619
1620 <varlistentry id="collation-managing-create-icu-und-u-co-emoji-x-icu">
1621 <term><literal>CREATE COLLATION "und-u-co-emoji-x-icu" (provider = icu, locale = 'und-u-co-emoji');</literal></term>
1622 <listitem>
1623 <para>
1624 Root collation with Emoji collation type, per Unicode Technical Standard #51
1625 </para>
1626 </listitem>
1627 </varlistentry>
1628
1629 <varlistentry id="collation-managing-create-icu-en-u-kr-grek-latn">
1630 <term><literal>CREATE COLLATION latinlast (provider = icu, locale = 'en-u-kr-grek-latn');</literal></term>
1631 <listitem>
1632 <para>
1633 Sort Greek letters before Latin ones. (The default is Latin before Greek.)
1634 </para>
1635 </listitem>
1636 </varlistentry>
1637
1638 <varlistentry id="collation-managing-create-icu-en-u-kf-upper">
1639 <term><literal>CREATE COLLATION upperfirst (provider = icu, locale = 'en-u-kf-upper');</literal></term>
1640 <listitem>
1641 <para>
1642 Sort upper-case letters before lower-case letters. (The default is
1643 lower-case letters first.)
1644 </para>
1645 </listitem>
1646 </varlistentry>
1647
1648 <varlistentry id="collation-managing-create-icu-en-u-kf-upper-kr-grek-latn">
1649 <term><literal>CREATE COLLATION special (provider = icu, locale = 'en-u-kf-upper-kr-grek-latn');</literal></term>
1650 <listitem>
1651 <para>
1652 Combines both of the above options.
1653 </para>
1654 </listitem>
1655 </varlistentry>
1656 </variablelist>
1657 </sect3>
1658
1659 <sect3 id="icu-tailoring-rules">
1660 <title>ICU Tailoring Rules</title>
1661
1662 <para>
1663 If the options provided by the collation settings shown above are not
1664 sufficient, the order of collation elements can be changed with tailoring
1665 rules, whose syntax is detailed at <ulink
1666 url="https://unicode-org.github.io/icu/userguide/collation/customization/"></ulink>.
1667 </para>
1668
1669 <para>
1670 This small example creates a collation based on the root locale with a
1671 tailoring rule:
1672 <programlisting>
1673 <![CDATA[CREATE COLLATION custom (provider = icu, locale = 'und', rules = '&V << w <<< W');]]>
1674 </programlisting>
1675 With this rule, the letter <quote>W</quote> is sorted after
1676 <quote>V</quote>, but is treated as a secondary difference similar to an
1677 accent. Rules like this are contained in the locale definitions of some
1678 languages. (Of course, if a locale definition already contains the
1679 desired rules, then they don't need to be specified again explicitly.)
1680 </para>
1681
1682 <para>
1683 Here is a more complex example. The following statement sets up a
1684 collation named <literal>ebcdic</literal> with rules to sort US-ASCII
1685 characters in the order of the EBCDIC encoding.
1686
1687 <programlisting>
1688 <![CDATA[CREATE COLLATION ebcdic (provider = icu, locale = 'und',
1689 rules = $$
1690 & ' ' < '.' < '<' < '(' < '+' < \|
1691 < '&' < '!' < '$' < '*' < ')' < ';'
1692 < '-' < '/' < ',' < '%' < '_' < '>' < '?'
1693 < '`' < ':' < '#' < '@' < \' < '=' < '"'
1694 <*a-r < '~' <*s-z < '^' < '[' < ']'
1695 < '{' <*A-I < '}' <*J-R < '\' <*S-Z <*0-9
1696 $$);]]>
1697
1698 SELECT c
1699 FROM (VALUES ('a'), ('b'), ('A'), ('B'), ('1'), ('2'), ('!'), ('^')) AS x(c)
1700 ORDER BY c COLLATE ebcdic;
1701 c
1702 ---
1703 !
1704 a
1705 b
1706 ^
1707 A
1708 B
1709 1
1710 2
1711 </programlisting>
1712 </para>
1713 </sect3>
1714
1715 <sect3 id="icu-external-references">
1716 <title>External References for ICU</title>
1717
1718 <para>
1719 This section (<xref linkend="icu-custom-collations"/>) is only a brief
1720 overview of ICU behavior and language tags. Refer to the following
1721 documents for technical details, additional options, and new behavior:
1722 </para>
1723
1724 <itemizedlist>
1725 <listitem>
1726 <para>
1727 <ulink url="https://www.unicode.org/reports/tr35/tr35-collation.html">Unicode Technical Standard #35</ulink>
1728 </para>
1729 </listitem>
1730 <listitem>
1731 <para>
1732 <ulink url="https://www.rfc-editor.org/info/bcp47">BCP 47</ulink>
1733 </para>
1734 </listitem>
1735 <listitem>
1736 <para>
1737 <ulink url="https://github.com/unicode-org/cldr/blob/master/common/bcp47/collation.xml">CLDR repository</ulink>
1738 </para>
1739 </listitem>
1740 <listitem>
1741 <para>
1742 <ulink url="https://unicode-org.github.io/icu/userguide/locale/"></ulink>
1743 </para>
1744 </listitem>
1745 <listitem>
1746 <para>
1747 <ulink url="https://unicode-org.github.io/icu/userguide/collation/"></ulink>
1748 </para>
1749 </listitem>
1750 </itemizedlist>
1751 </sect3>
1752 </sect2>
1753 </sect1>
1754
1755 <sect1 id="multibyte">
1756 <title>Character Set Support</title>
1757
1758 <indexterm zone="multibyte"><primary>character set</primary></indexterm>
1759
1760 <para>
1761 The character set support in <productname>PostgreSQL</productname>
1762 allows you to store text in a variety of character sets (also called
1763 encodings), including
1764 single-byte character sets such as the ISO 8859 series and
1765 multiple-byte character sets such as <acronym>EUC</acronym> (Extended Unix
1766 Code), UTF-8, and Mule internal code. All supported character sets
1767 can be used transparently by clients, but a few are not supported
1768 for use within the server (that is, as a server-side encoding).
1769 The default character set is selected while
1770 initializing your <productname>PostgreSQL</productname> database
1771 cluster using <command>initdb</command>. It can be overridden when you
1772 create a database, so you can have multiple
1773 databases each with a different character set.
1774 </para>
1775
1776 <para>
1777 An important restriction, however, is that each database's character set
1778 must be compatible with the database's <envar>LC_CTYPE</envar> (character
1779 classification) and <envar>LC_COLLATE</envar> (string sort order) locale
1780 settings. For <literal>C</literal> or
1781 <literal>POSIX</literal> locale, any character set is allowed, but for other
1782 libc-provided locales there is only one character set that will work
1783 correctly.
1784 (On Windows, however, UTF-8 encoding can be used with any locale.)
1785 If you have ICU support configured, ICU-provided locales can be used
1786 with most but not all server-side encodings.
1787 </para>
1788
1789 <sect2 id="multibyte-charset-supported">
1790 <title>Supported Character Sets</title>
1791
1792 <para>
1793 <xref linkend="charset-table"/> shows the character sets available
1794 for use in <productname>PostgreSQL</productname>.
1795 </para>
1796
1797 <table id="charset-table">
1798 <title><productname>PostgreSQL</productname> Character Sets</title>
1799 <tgroup cols="7">
1800 <colspec colname="col1" colwidth="3*"/>
1801 <colspec colname="col2" colwidth="2*"/>
1802 <colspec colname="col3" colwidth="2*"/>
1803 <colspec colname="col4" colwidth="1.25*"/>
1804 <colspec colname="col5" colwidth="1*"/>
1805 <colspec colname="col6" colwidth="1*"/>
1806 <colspec colname="col7" colwidth="2*"/>
1807 <thead>
1808 <row>
1809 <entry>Name</entry>
1810 <entry>Description</entry>
1811 <entry>Language</entry>
1812 <entry>Server?</entry>
1813 <entry>ICU?</entry>
1814 <!--
1815 The Bytes/Char field is populated by looking at the values returned
1816 by pg_wchar_table.mblen function for each encoding.
1817 -->
1818 <entry>Bytes/&zwsp;Char</entry>
1819 <entry>Aliases</entry>
1820 </row>
1821 </thead>
1822 <tbody>
1823 <row>
1824 <entry><literal>BIG5</literal></entry>
1825 <entry>Big Five</entry>
1826 <entry>Traditional Chinese</entry>
1827 <entry>No</entry>
1828 <entry>No</entry>
1829 <entry>1&ndash;2</entry>
1830 <entry><literal>WIN950</literal>, <literal>Windows950</literal></entry>
1831 </row>
1832 <row>
1833 <entry><literal>EUC_CN</literal></entry>
1834 <entry>Extended UNIX Code-CN</entry>
1835 <entry>Simplified Chinese</entry>
1836 <entry>Yes</entry>
1837 <entry>Yes</entry>
1838 <entry>1&ndash;3</entry>
1839 <entry></entry>
1840 </row>
1841 <row>
1842 <entry><literal>EUC_JP</literal></entry>
1843 <entry>Extended UNIX Code-JP</entry>
1844 <entry>Japanese</entry>
1845 <entry>Yes</entry>
1846 <entry>Yes</entry>
1847 <entry>1&ndash;3</entry>
1848 <entry></entry>
1849 </row>
1850 <row>
1851 <entry><literal>EUC_JIS_2004</literal></entry>
1852 <entry>Extended UNIX Code-JP, JIS X 0213</entry>
1853 <entry>Japanese</entry>
1854 <entry>Yes</entry>
1855 <entry>No</entry>
1856 <entry>1&ndash;3</entry>
1857 <entry></entry>
1858 </row>
1859 <row>
1860 <entry><literal>EUC_KR</literal></entry>
1861 <entry>Extended UNIX Code-KR</entry>
1862 <entry>Korean</entry>
1863 <entry>Yes</entry>
1864 <entry>Yes</entry>
1865 <entry>1&ndash;3</entry>
1866 <entry></entry>
1867 </row>
1868 <row>
1869 <entry><literal>EUC_TW</literal></entry>
1870 <entry>Extended UNIX Code-TW</entry>
1871 <entry>Traditional Chinese, Taiwanese</entry>
1872 <entry>Yes</entry>
1873 <entry>Yes</entry>
1874 <entry>1&ndash;4</entry>
1875 <entry></entry>
1876 </row>
1877 <row>
1878 <entry><literal>GB18030</literal></entry>
1879 <entry>National Standard</entry>
1880 <entry>Chinese</entry>
1881 <entry>No</entry>
1882 <entry>No</entry>
1883 <entry>1&ndash;4</entry>
1884 <entry></entry>
1885 </row>
1886 <row>
1887 <entry><literal>GBK</literal></entry>
1888 <entry>Extended National Standard</entry>
1889 <entry>Simplified Chinese</entry>
1890 <entry>No</entry>
1891 <entry>No</entry>
1892 <entry>1&ndash;2</entry>
1893 <entry><literal>WIN936</literal>, <literal>Windows936</literal></entry>
1894 </row>
1895 <row>
1896 <entry><literal>ISO_8859_5</literal></entry>
1897 <entry>ISO 8859-5, <acronym>ECMA</acronym> 113</entry>
1898 <entry>Latin/Cyrillic</entry>
1899 <entry>Yes</entry>
1900 <entry>Yes</entry>
1901 <entry>1</entry>
1902 <entry></entry>
1903 </row>
1904 <row>
1905 <entry><literal>ISO_8859_6</literal></entry>
1906 <entry>ISO 8859-6, <acronym>ECMA</acronym> 114</entry>
1907 <entry>Latin/Arabic</entry>
1908 <entry>Yes</entry>
1909 <entry>Yes</entry>
1910 <entry>1</entry>
1911 <entry></entry>
1912 </row>
1913 <row>
1914 <entry><literal>ISO_8859_7</literal></entry>
1915 <entry>ISO 8859-7, <acronym>ECMA</acronym> 118</entry>
1916 <entry>Latin/Greek</entry>
1917 <entry>Yes</entry>
1918 <entry>Yes</entry>
1919 <entry>1</entry>
1920 <entry></entry>
1921 </row>
1922 <row>
1923 <entry><literal>ISO_8859_8</literal></entry>
1924 <entry>ISO 8859-8, <acronym>ECMA</acronym> 121</entry>
1925 <entry>Latin/Hebrew</entry>
1926 <entry>Yes</entry>
1927 <entry>Yes</entry>
1928 <entry>1</entry>
1929 <entry></entry>
1930 </row>
1931 <row>
1932 <entry><literal>JOHAB</literal></entry>
1933 <entry><acronym>JOHAB</acronym></entry>
1934 <entry>Korean (Hangul)</entry>
1935 <entry>No</entry>
1936 <entry>No</entry>
1937 <entry>1&ndash;3</entry>
1938 <entry></entry>
1939 </row>
1940 <row>
1941 <entry><literal>KOI8R</literal></entry>
1942 <entry><acronym>KOI</acronym>8-R</entry>
1943 <entry>Cyrillic (Russian)</entry>
1944 <entry>Yes</entry>
1945 <entry>Yes</entry>
1946 <entry>1</entry>
1947 <entry><literal>KOI8</literal></entry>
1948 </row>
1949 <row>
1950 <entry><literal>KOI8U</literal></entry>
1951 <entry><acronym>KOI</acronym>8-U</entry>
1952 <entry>Cyrillic (Ukrainian)</entry>
1953 <entry>Yes</entry>
1954 <entry>Yes</entry>
1955 <entry>1</entry>
1956 <entry></entry>
1957 </row>
1958 <row>
1959 <entry><literal>LATIN1</literal></entry>
1960 <entry>ISO 8859-1, <acronym>ECMA</acronym> 94</entry>
1961 <entry>Western European</entry>
1962 <entry>Yes</entry>
1963 <entry>Yes</entry>
1964 <entry>1</entry>
1965 <entry><literal>ISO88591</literal></entry>
1966 </row>
1967 <row>
1968 <entry><literal>LATIN2</literal></entry>
1969 <entry>ISO 8859-2, <acronym>ECMA</acronym> 94</entry>
1970 <entry>Central European</entry>
1971 <entry>Yes</entry>
1972 <entry>Yes</entry>
1973 <entry>1</entry>
1974 <entry><literal>ISO88592</literal></entry>
1975 </row>
1976 <row>
1977 <entry><literal>LATIN3</literal></entry>
1978 <entry>ISO 8859-3, <acronym>ECMA</acronym> 94</entry>
1979 <entry>South European</entry>
1980 <entry>Yes</entry>
1981 <entry>Yes</entry>
1982 <entry>1</entry>
1983 <entry><literal>ISO88593</literal></entry>
1984 </row>
1985 <row>
1986 <entry><literal>LATIN4</literal></entry>
1987 <entry>ISO 8859-4, <acronym>ECMA</acronym> 94</entry>
1988 <entry>North European</entry>
1989 <entry>Yes</entry>
1990 <entry>Yes</entry>
1991 <entry>1</entry>
1992 <entry><literal>ISO88594</literal></entry>
1993 </row>
1994 <row>
1995 <entry><literal>LATIN5</literal></entry>
1996 <entry>ISO 8859-9, <acronym>ECMA</acronym> 128</entry>
1997 <entry>Turkish</entry>
1998 <entry>Yes</entry>
1999 <entry>Yes</entry>
2000 <entry>1</entry>
2001 <entry><literal>ISO88599</literal></entry>
2002 </row>
2003 <row>
2004 <entry><literal>LATIN6</literal></entry>
2005 <entry>ISO 8859-10, <acronym>ECMA</acronym> 144</entry>
2006 <entry>Nordic</entry>
2007 <entry>Yes</entry>
2008 <entry>Yes</entry>
2009 <entry>1</entry>
2010 <entry><literal>ISO885910</literal></entry>
2011 </row>
2012 <row>
2013 <entry><literal>LATIN7</literal></entry>
2014 <entry>ISO 8859-13</entry>
2015 <entry>Baltic</entry>
2016 <entry>Yes</entry>
2017 <entry>Yes</entry>
2018 <entry>1</entry>
2019 <entry><literal>ISO885913</literal></entry>
2020 </row>
2021 <row>
2022 <entry><literal>LATIN8</literal></entry>
2023 <entry>ISO 8859-14</entry>
2024 <entry>Celtic</entry>
2025 <entry>Yes</entry>
2026 <entry>Yes</entry>
2027 <entry>1</entry>
2028 <entry><literal>ISO885914</literal></entry>
2029 </row>
2030 <row>
2031 <entry><literal>LATIN9</literal></entry>
2032 <entry>ISO 8859-15</entry>
2033 <entry>LATIN1 with Euro and accents</entry>
2034 <entry>Yes</entry>
2035 <entry>Yes</entry>
2036 <entry>1</entry>
2037 <entry><literal>ISO885915</literal></entry>
2038 </row>
2039 <row>
2040 <entry><literal>LATIN10</literal></entry>
2041 <entry>ISO 8859-16, <acronym>ASRO</acronym> SR 14111</entry>
2042 <entry>Romanian</entry>
2043 <entry>Yes</entry>
2044 <entry>No</entry>
2045 <entry>1</entry>
2046 <entry><literal>ISO885916</literal></entry>
2047 </row>
2048 <row>
2049 <entry><literal>MULE_INTERNAL</literal></entry>
2050 <entry>Mule internal code</entry>
2051 <entry>Multilingual Emacs</entry>
2052 <entry>Yes</entry>
2053 <entry>No</entry>
2054 <entry>1&ndash;4</entry>
2055 <entry></entry>
2056 </row>
2057 <row>
2058 <entry><literal>SJIS</literal></entry>
2059 <entry>Shift JIS</entry>
2060 <entry>Japanese</entry>
2061 <entry>No</entry>
2062 <entry>No</entry>
2063 <entry>1&ndash;2</entry>
2064 <entry><literal>Mskanji</literal>, <literal>ShiftJIS</literal>, <literal>WIN932</literal>, <literal>Windows932</literal></entry>
2065 </row>
2066 <row>
2067 <entry><literal>SHIFT_JIS_2004</literal></entry>
2068 <entry>Shift JIS, JIS X 0213</entry>
2069 <entry>Japanese</entry>
2070 <entry>No</entry>
2071 <entry>No</entry>
2072 <entry>1&ndash;2</entry>
2073 <entry></entry>
2074 </row>
2075 <row>
2076 <entry><literal>SQL_ASCII</literal></entry>
2077 <entry>unspecified (see text)</entry>
2078 <entry><emphasis>any</emphasis></entry>
2079 <entry>Yes</entry>
2080 <entry>No</entry>
2081 <entry>1</entry>
2082 <entry></entry>
2083 </row>
2084 <row>
2085 <entry><literal>UHC</literal></entry>
2086 <entry>Unified Hangul Code</entry>
2087 <entry>Korean</entry>
2088 <entry>No</entry>
2089 <entry>No</entry>
2090 <entry>1&ndash;2</entry>
2091 <entry><literal>WIN949</literal>, <literal>Windows949</literal></entry>
2092 </row>
2093 <row>
2094 <entry><literal>UTF8</literal></entry>
2095 <entry>Unicode, 8-bit</entry>
2096 <entry><emphasis>all</emphasis></entry>
2097 <entry>Yes</entry>
2098 <entry>Yes</entry>
2099 <entry>1&ndash;4</entry>
2100 <entry><literal>Unicode</literal></entry>
2101 </row>
2102 <row>
2103 <entry><literal>WIN866</literal></entry>
2104 <entry>Windows CP866</entry>
2105 <entry>Cyrillic</entry>
2106 <entry>Yes</entry>
2107 <entry>Yes</entry>
2108 <entry>1</entry>
2109 <entry><literal>ALT</literal></entry>
2110 </row>
2111 <row>
2112 <entry><literal>WIN874</literal></entry>
2113 <entry>Windows CP874</entry>
2114 <entry>Thai</entry>
2115 <entry>Yes</entry>
2116 <entry>No</entry>
2117 <entry>1</entry>
2118 <entry></entry>
2119 </row>
2120 <row>
2121 <entry><literal>WIN1250</literal></entry>
2122 <entry>Windows CP1250</entry>
2123 <entry>Central European</entry>
2124 <entry>Yes</entry>
2125 <entry>Yes</entry>
2126 <entry>1</entry>
2127 <entry></entry>
2128 </row>
2129 <row>
2130 <entry><literal>WIN1251</literal></entry>
2131 <entry>Windows CP1251</entry>
2132 <entry>Cyrillic</entry>
2133 <entry>Yes</entry>
2134 <entry>Yes</entry>
2135 <entry>1</entry>
2136 <entry><literal>WIN</literal></entry>
2137 </row>
2138 <row>
2139 <entry><literal>WIN1252</literal></entry>
2140 <entry>Windows CP1252</entry>
2141 <entry>Western European</entry>
2142 <entry>Yes</entry>
2143 <entry>Yes</entry>
2144 <entry>1</entry>
2145 <entry></entry>
2146 </row>
2147 <row>
2148 <entry><literal>WIN1253</literal></entry>
2149 <entry>Windows CP1253</entry>
2150 <entry>Greek</entry>
2151 <entry>Yes</entry>
2152 <entry>Yes</entry>
2153 <entry>1</entry>
2154 <entry></entry>
2155 </row>
2156 <row>
2157 <entry><literal>WIN1254</literal></entry>
2158 <entry>Windows CP1254</entry>
2159 <entry>Turkish</entry>
2160 <entry>Yes</entry>
2161 <entry>Yes</entry>
2162 <entry>1</entry>
2163 <entry></entry>
2164 </row>
2165 <row>
2166 <entry><literal>WIN1255</literal></entry>
2167 <entry>Windows CP1255</entry>
2168 <entry>Hebrew</entry>
2169 <entry>Yes</entry>
2170 <entry>Yes</entry>
2171 <entry>1</entry>
2172 <entry></entry>
2173 </row>
2174 <row>
2175 <entry><literal>WIN1256</literal></entry>
2176 <entry>Windows CP1256</entry>
2177 <entry>Arabic</entry>
2178 <entry>Yes</entry>
2179 <entry>Yes</entry>
2180 <entry>1</entry>
2181 <entry></entry>
2182 </row>
2183 <row>
2184 <entry><literal>WIN1257</literal></entry>
2185 <entry>Windows CP1257</entry>
2186 <entry>Baltic</entry>
2187 <entry>Yes</entry>
2188 <entry>Yes</entry>
2189 <entry>1</entry>
2190 <entry></entry>
2191 </row>
2192 <row>
2193 <entry><literal>WIN1258</literal></entry>
2194 <entry>Windows CP1258</entry>
2195 <entry>Vietnamese</entry>
2196 <entry>Yes</entry>
2197 <entry>Yes</entry>
2198 <entry>1</entry>
2199 <entry><literal>ABC</literal>, <literal>TCVN</literal>, <literal>TCVN5712</literal>, <literal>VSCII</literal></entry>
2200 </row>
2201 </tbody>
2202 </tgroup>
2203 </table>
2204
2205 <para>
2206 Not all client <acronym>API</acronym>s support all the listed character sets. For example, the
2207 <productname>PostgreSQL</productname>
2208 JDBC driver does not support <literal>MULE_INTERNAL</literal>, <literal>LATIN6</literal>,
2209 <literal>LATIN8</literal>, and <literal>LATIN10</literal>.
2210 </para>
2211
2212 <para>
2213 The <literal>SQL_ASCII</literal> setting behaves considerably differently
2214 from the other settings. When the server character set is
2215 <literal>SQL_ASCII</literal>, the server interprets byte values 0&ndash;127
2216 according to the ASCII standard, while byte values 128&ndash;255 are taken
2217 as uninterpreted characters. No encoding conversion will be done when
2218 the setting is <literal>SQL_ASCII</literal>. Thus, this setting is not so
2219 much a declaration that a specific encoding is in use, as a declaration
2220 of ignorance about the encoding. In most cases, if you are
2221 working with any non-ASCII data, it is unwise to use the
2222 <literal>SQL_ASCII</literal> setting because
2223 <productname>PostgreSQL</productname> will be unable to help you by
2224 converting or validating non-ASCII characters.
2225 </para>
2226 </sect2>
2227
2228 <sect2 id="multibyte-setting">
2229 <title>Setting the Character Set</title>
2230
2231 <para>
2232 <command>initdb</command> defines the default character set (encoding)
2233 for a <productname>PostgreSQL</productname> cluster. For example,
2234
2235 <screen>
2236 initdb -E EUC_JP
2237 </screen>
2238
2239 sets the default character set to
2240 <literal>EUC_JP</literal> (Extended Unix Code for Japanese). You
2241 can use <option>--encoding</option> instead of
2242 <option>-E</option> if you prefer longer option strings.
2243 If no <option>-E</option> or <option>--encoding</option> option is
2244 given, <command>initdb</command> attempts to determine the appropriate
2245 encoding to use based on the specified or default locale.
2246 </para>
2247
2248 <para>
2249 You can specify a non-default encoding at database creation time,
2250 provided that the encoding is compatible with the selected locale:
2251
2252 <screen>
2253 createdb -E EUC_KR -T template0 --lc-collate=ko_KR.euckr --lc-ctype=ko_KR.euckr korean
2254 </screen>
2255
2256 This will create a database named <literal>korean</literal> that
2257 uses the character set <literal>EUC_KR</literal>, and locale <literal>ko_KR</literal>.
2258 Another way to accomplish this is to use this SQL command:
2259
2260 <programlisting>
2261 CREATE DATABASE korean WITH ENCODING 'EUC_KR' LC_COLLATE='ko_KR.euckr' LC_CTYPE='ko_KR.euckr' TEMPLATE=template0;
2262 </programlisting>
2263
2264 Notice that the above commands specify copying the <literal>template0</literal>
2265 database. When copying any other database, the encoding and locale
2266 settings cannot be changed from those of the source database, because
2267 that might result in corrupt data. For more information see
2268 <xref linkend="manage-ag-templatedbs"/>.
2269 </para>
2270
2271 <para>
2272 The encoding for a database is stored in the system catalog
2273 <literal>pg_database</literal>. You can see it by using the
2274 <command>psql</command> <option>-l</option> option or the
2275 <command>\l</command> command.
2276
2277 <screen>
2278 $ <userinput>psql -l</userinput>
2279 List of databases
2280 Name | Owner | Encoding | Collation | Ctype | Access Privileges
2281 -----------+----------+-----------+-------------+-------------+-------------------------------------
2282 clocaledb | hlinnaka | SQL_ASCII | C | C |
2283 englishdb | hlinnaka | UTF8 | en_GB.UTF8 | en_GB.UTF8 |
2284 japanese | hlinnaka | UTF8 | ja_JP.UTF8 | ja_JP.UTF8 |
2285 korean | hlinnaka | EUC_KR | ko_KR.euckr | ko_KR.euckr |
2286 postgres | hlinnaka | UTF8 | fi_FI.UTF8 | fi_FI.UTF8 |
2287 template0 | hlinnaka | UTF8 | fi_FI.UTF8 | fi_FI.UTF8 | {=c/hlinnaka,hlinnaka=CTc/hlinnaka}
2288 template1 | hlinnaka | UTF8 | fi_FI.UTF8 | fi_FI.UTF8 | {=c/hlinnaka,hlinnaka=CTc/hlinnaka}
2289 (7 rows)
2290 </screen>
2291 </para>
2292
2293 <important>
2294 <para>
2295 On most modern operating systems, <productname>PostgreSQL</productname>
2296 can determine which character set is implied by the <envar>LC_CTYPE</envar>
2297 setting, and it will enforce that only the matching database encoding is
2298 used. On older systems it is your responsibility to ensure that you use
2299 the encoding expected by the locale you have selected. A mistake in
2300 this area is likely to lead to strange behavior of locale-dependent
2301 operations such as sorting.
2302 </para>
2303
2304 <para>
2305 <productname>PostgreSQL</productname> will allow superusers to create
2306 databases with <literal>SQL_ASCII</literal> encoding even when
2307 <envar>LC_CTYPE</envar> is not <literal>C</literal> or <literal>POSIX</literal>. As noted
2308 above, <literal>SQL_ASCII</literal> does not enforce that the data stored in
2309 the database has any particular encoding, and so this choice poses risks
2310 of locale-dependent misbehavior. Using this combination of settings is
2311 deprecated and may someday be forbidden altogether.
2312 </para>
2313 </important>
2314 </sect2>
2315
2316 <sect2 id="multibyte-automatic-conversion">
2317 <title>Automatic Character Set Conversion Between Server and Client</title>
2318
2319 <para>
2320 <productname>PostgreSQL</productname> supports automatic character
2321 set conversion between server and client for many combinations of
2322 character sets (<xref linkend="multibyte-conversions-supported"/>
2323 shows which ones).
2324 </para>
2325
2326 <para>
2327 To enable automatic character set conversion, you have to
2328 tell <productname>PostgreSQL</productname> the character set
2329 (encoding) you would like to use in the client. There are several
2330 ways to accomplish this:
2331
2332 <itemizedlist>
2333 <listitem>
2334 <para>
2335 Using the <command>\encoding</command> command in
2336 <application>psql</application>.
2337 <command>\encoding</command> allows you to change client
2338 encoding on the fly. For
2339 example, to change the encoding to <literal>SJIS</literal>, type:
2340
2341 <programlisting>
2342 \encoding SJIS
2343 </programlisting>
2344 </para>
2345 </listitem>
2346
2347 <listitem>
2348 <para>
2349 <application>libpq</application> (<xref linkend="libpq-control"/>) has functions to control the client encoding.
2350 </para>
2351 </listitem>
2352
2353 <listitem>
2354 <para>
2355 Using <command>SET client_encoding TO</command>.
2356
2357 Setting the client encoding can be done with this SQL command:
2358
2359 <programlisting>
2360 SET CLIENT_ENCODING TO '<replaceable>value</replaceable>';
2361 </programlisting>
2362
2363 Also you can use the standard SQL syntax <literal>SET NAMES</literal>
2364 for this purpose:
2365
2366 <programlisting>
2367 SET NAMES '<replaceable>value</replaceable>';
2368 </programlisting>
2369
2370 To query the current client encoding:
2371
2372 <programlisting>
2373 SHOW client_encoding;
2374 </programlisting>
2375
2376 To return to the default encoding:
2377
2378 <programlisting>
2379 RESET client_encoding;
2380 </programlisting>
2381 </para>
2382 </listitem>
2383
2384 <listitem>
2385 <para>
2386 Using <envar>PGCLIENTENCODING</envar>. If the environment variable
2387 <envar>PGCLIENTENCODING</envar> is defined in the client's
2388 environment, that client encoding is automatically selected
2389 when a connection to the server is made. (This can
2390 subsequently be overridden using any of the other methods
2391 mentioned above.)
2392 </para>
2393 </listitem>
2394
2395 <listitem>
2396 <para>
2397 Using the configuration variable <xref
2398 linkend="guc-client-encoding"/>. If the
2399 <varname>client_encoding</varname> variable is set, that client
2400 encoding is automatically selected when a connection to the
2401 server is made. (This can subsequently be overridden using any
2402 of the other methods mentioned above.)
2403 </para>
2404 </listitem>
2405
2406 </itemizedlist>
2407 </para>
2408
2409 <para>
2410 If the conversion of a particular character is not possible
2411 &mdash; suppose you chose <literal>EUC_JP</literal> for the
2412 server and <literal>LATIN1</literal> for the client, and some
2413 Japanese characters are returned that do not have a representation in
2414 <literal>LATIN1</literal> &mdash; an error is reported.
2415 </para>
2416
2417 <para>
2418 If the client character set is defined as <literal>SQL_ASCII</literal>,
2419 encoding conversion is disabled, regardless of the server's character
2420 set. (However, if the server's character set is
2421 not <literal>SQL_ASCII</literal>, the server will still check that
2422 incoming data is valid for that encoding; so the net effect is as
2423 though the client character set were the same as the server's.)
2424 Just as for the server, use of <literal>SQL_ASCII</literal> is unwise
2425 unless you are working with all-ASCII data.
2426 </para>
2427 </sect2>
2428
2429 <sect2 id="multibyte-conversions-supported">
2430 <title>Available Character Set Conversions</title>
2431
2432 <para>
2433 <productname>PostgreSQL</productname> allows conversion between any
2434 two character sets for which a conversion function is listed in the
2435 <link linkend="catalog-pg-conversion"><structname>pg_conversion</structname></link>
2436 system catalog. <productname>PostgreSQL</productname> comes with
2437 some predefined conversions, as summarized in
2438 <xref linkend="multibyte-translation-table"/> and shown in more
2439 detail in <xref linkend="builtin-conversions-table"/>. You can
2440 create a new conversion using the SQL command
2441 <xref linkend="sql-createconversion"/>. (To be used for automatic
2442 client/server conversions, a conversion must be marked
2443 as <quote>default</quote> for its character set pair.)
2444 </para>
2445
2446 <table id="multibyte-translation-table">
2447 <title>Built-in Client/Server Character Set Conversions</title>
2448 <tgroup cols="2">
2449 <colspec colname="col1" colwidth="1*"/>
2450 <colspec colname="col2" colwidth="3*"/>
2451 <thead>
2452 <row>
2453 <entry>Server Character Set</entry>
2454 <entry>Available Client Character Sets</entry>
2455 </row>
2456 </thead>
2457 <tbody>
2458 <row>
2459 <entry><literal>BIG5</literal></entry>
2460 <entry><emphasis>not supported as a server encoding</emphasis>
2461 </entry>
2462 </row>
2463 <row>
2464 <entry><literal>EUC_CN</literal></entry>
2465 <entry><emphasis>EUC_CN</emphasis>,
2466 <literal>MULE_INTERNAL</literal>,
2467 <literal>UTF8</literal>
2468 </entry>
2469 </row>
2470 <row>
2471 <entry><literal>EUC_JP</literal></entry>
2472 <entry><emphasis>EUC_JP</emphasis>,
2473 <literal>MULE_INTERNAL</literal>,
2474 <literal>SJIS</literal>,
2475 <literal>UTF8</literal>
2476 </entry>
2477 </row>
2478 <row>
2479 <entry><literal>EUC_JIS_2004</literal></entry>
2480 <entry><emphasis>EUC_JIS_2004</emphasis>,
2481 <literal>SHIFT_JIS_2004</literal>,
2482 <literal>UTF8</literal>
2483 </entry>
2484 </row>
2485 <row>
2486 <entry><literal>EUC_KR</literal></entry>
2487 <entry><emphasis>EUC_KR</emphasis>,
2488 <literal>MULE_INTERNAL</literal>,
2489 <literal>UTF8</literal>
2490 </entry>
2491 </row>
2492 <row>
2493 <entry><literal>EUC_TW</literal></entry>
2494 <entry><emphasis>EUC_TW</emphasis>,
2495 <literal>BIG5</literal>,
2496 <literal>MULE_INTERNAL</literal>,
2497 <literal>UTF8</literal>
2498 </entry>
2499 </row>
2500 <row>
2501 <entry><literal>GB18030</literal></entry>
2502 <entry><emphasis>not supported as a server encoding</emphasis>
2503 </entry>
2504 </row>
2505 <row>
2506 <entry><literal>GBK</literal></entry>
2507 <entry><emphasis>not supported as a server encoding</emphasis>
2508 </entry>
2509 </row>
2510 <row>
2511 <entry><literal>ISO_8859_5</literal></entry>
2512 <entry><emphasis>ISO_8859_5</emphasis>,
2513 <literal>KOI8R</literal>,
2514 <literal>MULE_INTERNAL</literal>,
2515 <literal>UTF8</literal>,
2516 <literal>WIN866</literal>,
2517 <literal>WIN1251</literal>
2518 </entry>
2519 </row>
2520 <row>
2521 <entry><literal>ISO_8859_6</literal></entry>
2522 <entry><emphasis>ISO_8859_6</emphasis>,
2523 <literal>UTF8</literal>
2524 </entry>
2525 </row>
2526 <row>
2527 <entry><literal>ISO_8859_7</literal></entry>
2528 <entry><emphasis>ISO_8859_7</emphasis>,
2529 <literal>UTF8</literal>
2530 </entry>
2531 </row>
2532 <row>
2533 <entry><literal>ISO_8859_8</literal></entry>
2534 <entry><emphasis>ISO_8859_8</emphasis>,
2535 <literal>UTF8</literal>
2536 </entry>
2537 </row>
2538 <row>
2539 <entry><literal>JOHAB</literal></entry>
2540 <entry><emphasis>not supported as a server encoding</emphasis>
2541 </entry>
2542 </row>
2543 <row>
2544 <entry><literal>KOI8R</literal></entry>
2545 <entry><emphasis>KOI8R</emphasis>,
2546 <literal>ISO_8859_5</literal>,
2547 <literal>MULE_INTERNAL</literal>,
2548 <literal>UTF8</literal>,
2549 <literal>WIN866</literal>,
2550 <literal>WIN1251</literal>
2551 </entry>
2552 </row>
2553 <row>
2554 <entry><literal>KOI8U</literal></entry>
2555 <entry><emphasis>KOI8U</emphasis>,
2556 <literal>UTF8</literal>
2557 </entry>
2558 </row>
2559 <row>
2560 <entry><literal>LATIN1</literal></entry>
2561 <entry><emphasis>LATIN1</emphasis>,
2562 <literal>MULE_INTERNAL</literal>,
2563 <literal>UTF8</literal>
2564 </entry>
2565 </row>
2566 <row>
2567 <entry><literal>LATIN2</literal></entry>
2568 <entry><emphasis>LATIN2</emphasis>,
2569 <literal>MULE_INTERNAL</literal>,
2570 <literal>UTF8</literal>,
2571 <literal>WIN1250</literal>
2572 </entry>
2573 </row>
2574 <row>
2575 <entry><literal>LATIN3</literal></entry>
2576 <entry><emphasis>LATIN3</emphasis>,
2577 <literal>MULE_INTERNAL</literal>,
2578 <literal>UTF8</literal>
2579 </entry>
2580 </row>
2581 <row>
2582 <entry><literal>LATIN4</literal></entry>
2583 <entry><emphasis>LATIN4</emphasis>,
2584 <literal>MULE_INTERNAL</literal>,
2585 <literal>UTF8</literal>
2586 </entry>
2587 </row>
2588 <row>
2589 <entry><literal>LATIN5</literal></entry>
2590 <entry><emphasis>LATIN5</emphasis>,
2591 <literal>UTF8</literal>
2592 </entry>
2593 </row>
2594 <row>
2595 <entry><literal>LATIN6</literal></entry>
2596 <entry><emphasis>LATIN6</emphasis>,
2597 <literal>UTF8</literal>
2598 </entry>
2599 </row>
2600 <row>
2601 <entry><literal>LATIN7</literal></entry>
2602 <entry><emphasis>LATIN7</emphasis>,
2603 <literal>UTF8</literal>
2604 </entry>
2605 </row>
2606 <row>
2607 <entry><literal>LATIN8</literal></entry>
2608 <entry><emphasis>LATIN8</emphasis>,
2609 <literal>UTF8</literal>
2610 </entry>
2611 </row>
2612 <row>
2613 <entry><literal>LATIN9</literal></entry>
2614 <entry><emphasis>LATIN9</emphasis>,
2615 <literal>UTF8</literal>
2616 </entry>
2617 </row>
2618 <row>
2619 <entry><literal>LATIN10</literal></entry>
2620 <entry><emphasis>LATIN10</emphasis>,
2621 <literal>UTF8</literal>
2622 </entry>
2623 </row>
2624 <row>
2625 <entry><literal>MULE_INTERNAL</literal></entry>
2626 <entry><emphasis>MULE_INTERNAL</emphasis>,
2627 <literal>BIG5</literal>,
2628 <literal>EUC_CN</literal>,
2629 <literal>EUC_JP</literal>,
2630 <literal>EUC_KR</literal>,
2631 <literal>EUC_TW</literal>,
2632 <literal>ISO_8859_5</literal>,
2633 <literal>KOI8R</literal>,
2634 <literal>LATIN1</literal> to <literal>LATIN4</literal>,
2635 <literal>SJIS</literal>,
2636 <literal>WIN866</literal>,
2637 <literal>WIN1250</literal>,
2638 <literal>WIN1251</literal>
2639 </entry>
2640 </row>
2641 <row>
2642 <entry><literal>SJIS</literal></entry>
2643 <entry><emphasis>not supported as a server encoding</emphasis>
2644 </entry>
2645 </row>
2646 <row>
2647 <entry><literal>SHIFT_JIS_2004</literal></entry>
2648 <entry><emphasis>not supported as a server encoding</emphasis>
2649 </entry>
2650 </row>
2651 <row>
2652 <entry><literal>SQL_ASCII</literal></entry>
2653 <entry><emphasis>any (no conversion will be performed)</emphasis>
2654 </entry>
2655 </row>
2656 <row>
2657 <entry><literal>UHC</literal></entry>
2658 <entry><emphasis>not supported as a server encoding</emphasis>
2659 </entry>
2660 </row>
2661 <row>
2662 <entry><literal>UTF8</literal></entry>
2663 <entry><emphasis>all supported encodings</emphasis>
2664 </entry>
2665 </row>
2666 <row>
2667 <entry><literal>WIN866</literal></entry>
2668 <entry><emphasis>WIN866</emphasis>,
2669 <literal>ISO_8859_5</literal>,
2670 <literal>KOI8R</literal>,
2671 <literal>MULE_INTERNAL</literal>,
2672 <literal>UTF8</literal>,
2673 <literal>WIN1251</literal>
2674 </entry>
2675 </row>
2676 <row>
2677 <entry><literal>WIN874</literal></entry>
2678 <entry><emphasis>WIN874</emphasis>,
2679 <literal>UTF8</literal>
2680 </entry>
2681 </row>
2682 <row>
2683 <entry><literal>WIN1250</literal></entry>
2684 <entry><emphasis>WIN1250</emphasis>,
2685 <literal>LATIN2</literal>,
2686 <literal>MULE_INTERNAL</literal>,
2687 <literal>UTF8</literal>
2688 </entry>
2689 </row>
2690 <row>
2691 <entry><literal>WIN1251</literal></entry>
2692 <entry><emphasis>WIN1251</emphasis>,
2693 <literal>ISO_8859_5</literal>,
2694 <literal>KOI8R</literal>,
2695 <literal>MULE_INTERNAL</literal>,
2696 <literal>UTF8</literal>,
2697 <literal>WIN866</literal>
2698 </entry>
2699 </row>
2700 <row>
2701 <entry><literal>WIN1252</literal></entry>
2702 <entry><emphasis>WIN1252</emphasis>,
2703 <literal>UTF8</literal>
2704 </entry>
2705 </row>
2706 <row>
2707 <entry><literal>WIN1253</literal></entry>
2708 <entry><emphasis>WIN1253</emphasis>,
2709 <literal>UTF8</literal>
2710 </entry>
2711 </row>
2712 <row>
2713 <entry><literal>WIN1254</literal></entry>
2714 <entry><emphasis>WIN1254</emphasis>,
2715 <literal>UTF8</literal>
2716 </entry>
2717 </row>
2718 <row>
2719 <entry><literal>WIN1255</literal></entry>
2720 <entry><emphasis>WIN1255</emphasis>,
2721 <literal>UTF8</literal>
2722 </entry>
2723 </row>
2724 <row>
2725 <entry><literal>WIN1256</literal></entry>
2726 <entry><emphasis>WIN1256</emphasis>,
2727 <literal>UTF8</literal>
2728 </entry>
2729 </row>
2730 <row>
2731 <entry><literal>WIN1257</literal></entry>
2732 <entry><emphasis>WIN1257</emphasis>,
2733 <literal>UTF8</literal>
2734 </entry>
2735 </row>
2736 <row>
2737 <entry><literal>WIN1258</literal></entry>
2738 <entry><emphasis>WIN1258</emphasis>,
2739 <literal>UTF8</literal>
2740 </entry>
2741 </row>
2742 </tbody>
2743 </tgroup>
2744 </table>
2745
2746 <table id="builtin-conversions-table">
2747 <title>All Built-in Character Set Conversions</title>
2748 <tgroup cols="3">
2749 <colspec colname="col1" colwidth="2*"/>
2750 <colspec colname="col2" colwidth="1*"/>
2751 <colspec colname="col3" colwidth="1*"/>
2752 <thead>
2753 <row>
2754 <entry>Conversion Name
2755 <footnote>
2756 <para>
2757 The conversion names follow a standard naming scheme: The
2758 official name of the source encoding with all
2759 non-alphanumeric characters replaced by underscores, followed
2760 by <literal>_to_</literal>, followed by the similarly processed
2761 destination encoding name. Therefore, these names sometimes
2762 deviate from the customary encoding names shown in
2763 <xref linkend="charset-table"/>.
2764 </para>
2765 </footnote>
2766 </entry>
2767 <entry>Source Encoding</entry>
2768 <entry>Destination Encoding</entry>
2769 </row>
2770 </thead>
2771
2772 <tbody>
2773 <row>
2774 <entry><literal>big5_to_euc_tw</literal></entry>
2775 <entry><literal>BIG5</literal></entry>
2776 <entry><literal>EUC_TW</literal></entry>
2777 </row>
2778 <row>
2779 <entry><literal>big5_to_mic</literal></entry>
2780 <entry><literal>BIG5</literal></entry>
2781 <entry><literal>MULE_INTERNAL</literal></entry>
2782 </row>
2783 <row>
2784 <entry><literal>big5_to_utf8</literal></entry>
2785 <entry><literal>BIG5</literal></entry>
2786 <entry><literal>UTF8</literal></entry>
2787 </row>
2788 <row>
2789 <entry><literal>euc_cn_to_mic</literal></entry>
2790 <entry><literal>EUC_CN</literal></entry>
2791 <entry><literal>MULE_INTERNAL</literal></entry>
2792 </row>
2793 <row>
2794 <entry><literal>euc_cn_to_utf8</literal></entry>
2795 <entry><literal>EUC_CN</literal></entry>
2796 <entry><literal>UTF8</literal></entry>
2797 </row>
2798 <row>
2799 <entry><literal>euc_jp_to_mic</literal></entry>
2800 <entry><literal>EUC_JP</literal></entry>
2801 <entry><literal>MULE_INTERNAL</literal></entry>
2802 </row>
2803 <row>
2804 <entry><literal>euc_jp_to_sjis</literal></entry>
2805 <entry><literal>EUC_JP</literal></entry>
2806 <entry><literal>SJIS</literal></entry>
2807 </row>
2808 <row>
2809 <entry><literal>euc_jp_to_utf8</literal></entry>
2810 <entry><literal>EUC_JP</literal></entry>
2811 <entry><literal>UTF8</literal></entry>
2812 </row>
2813 <row>
2814 <entry><literal>euc_kr_to_mic</literal></entry>
2815 <entry><literal>EUC_KR</literal></entry>
2816 <entry><literal>MULE_INTERNAL</literal></entry>
2817 </row>
2818 <row>
2819 <entry><literal>euc_kr_to_utf8</literal></entry>
2820 <entry><literal>EUC_KR</literal></entry>
2821 <entry><literal>UTF8</literal></entry>
2822 </row>
2823 <row>
2824 <entry><literal>euc_tw_to_big5</literal></entry>
2825 <entry><literal>EUC_TW</literal></entry>
2826 <entry><literal>BIG5</literal></entry>
2827 </row>
2828 <row>
2829 <entry><literal>euc_tw_to_mic</literal></entry>
2830 <entry><literal>EUC_TW</literal></entry>
2831 <entry><literal>MULE_INTERNAL</literal></entry>
2832 </row>
2833 <row>
2834 <entry><literal>euc_tw_to_utf8</literal></entry>
2835 <entry><literal>EUC_TW</literal></entry>
2836 <entry><literal>UTF8</literal></entry>
2837 </row>
2838 <row>
2839 <entry><literal>gb18030_to_utf8</literal></entry>
2840 <entry><literal>GB18030</literal></entry>
2841 <entry><literal>UTF8</literal></entry>
2842 </row>
2843 <row>
2844 <entry><literal>gbk_to_utf8</literal></entry>
2845 <entry><literal>GBK</literal></entry>
2846 <entry><literal>UTF8</literal></entry>
2847 </row>
2848 <row>
2849 <entry><literal>iso_8859_10_to_utf8</literal></entry>
2850 <entry><literal>LATIN6</literal></entry>
2851 <entry><literal>UTF8</literal></entry>
2852 </row>
2853 <row>
2854 <entry><literal>iso_8859_13_to_utf8</literal></entry>
2855 <entry><literal>LATIN7</literal></entry>
2856 <entry><literal>UTF8</literal></entry>
2857 </row>
2858 <row>
2859 <entry><literal>iso_8859_14_to_utf8</literal></entry>
2860 <entry><literal>LATIN8</literal></entry>
2861 <entry><literal>UTF8</literal></entry>
2862 </row>
2863 <row>
2864 <entry><literal>iso_8859_15_to_utf8</literal></entry>
2865 <entry><literal>LATIN9</literal></entry>
2866 <entry><literal>UTF8</literal></entry>
2867 </row>
2868 <row>
2869 <entry><literal>iso_8859_16_to_utf8</literal></entry>
2870 <entry><literal>LATIN10</literal></entry>
2871 <entry><literal>UTF8</literal></entry>
2872 </row>
2873 <row>
2874 <entry><literal>iso_8859_1_to_mic</literal></entry>
2875 <entry><literal>LATIN1</literal></entry>
2876 <entry><literal>MULE_INTERNAL</literal></entry>
2877 </row>
2878 <row>
2879 <entry><literal>iso_8859_1_to_utf8</literal></entry>
2880 <entry><literal>LATIN1</literal></entry>
2881 <entry><literal>UTF8</literal></entry>
2882 </row>
2883 <row>
2884 <entry><literal>iso_8859_2_to_mic</literal></entry>
2885 <entry><literal>LATIN2</literal></entry>
2886 <entry><literal>MULE_INTERNAL</literal></entry>
2887 </row>
2888 <row>
2889 <entry><literal>iso_8859_2_to_utf8</literal></entry>
2890 <entry><literal>LATIN2</literal></entry>
2891 <entry><literal>UTF8</literal></entry>
2892 </row>
2893 <row>
2894 <entry><literal>iso_8859_2_to_windows_1250</literal></entry>
2895 <entry><literal>LATIN2</literal></entry>
2896 <entry><literal>WIN1250</literal></entry>
2897 </row>
2898 <row>
2899 <entry><literal>iso_8859_3_to_mic</literal></entry>
2900 <entry><literal>LATIN3</literal></entry>
2901 <entry><literal>MULE_INTERNAL</literal></entry>
2902 </row>
2903 <row>
2904 <entry><literal>iso_8859_3_to_utf8</literal></entry>
2905 <entry><literal>LATIN3</literal></entry>
2906 <entry><literal>UTF8</literal></entry>
2907 </row>
2908 <row>
2909 <entry><literal>iso_8859_4_to_mic</literal></entry>
2910 <entry><literal>LATIN4</literal></entry>
2911 <entry><literal>MULE_INTERNAL</literal></entry>
2912 </row>
2913 <row>
2914 <entry><literal>iso_8859_4_to_utf8</literal></entry>
2915 <entry><literal>LATIN4</literal></entry>
2916 <entry><literal>UTF8</literal></entry>
2917 </row>
2918 <row>
2919 <entry><literal>iso_8859_5_to_koi8_r</literal></entry>
2920 <entry><literal>ISO_8859_5</literal></entry>
2921 <entry><literal>KOI8R</literal></entry>
2922 </row>
2923 <row>
2924 <entry><literal>iso_8859_5_to_mic</literal></entry>
2925 <entry><literal>ISO_8859_5</literal></entry>
2926 <entry><literal>MULE_INTERNAL</literal></entry>
2927 </row>
2928 <row>
2929 <entry><literal>iso_8859_5_to_utf8</literal></entry>
2930 <entry><literal>ISO_8859_5</literal></entry>
2931 <entry><literal>UTF8</literal></entry>
2932 </row>
2933 <row>
2934 <entry><literal>iso_8859_5_to_windows_1251</literal></entry>
2935 <entry><literal>ISO_8859_5</literal></entry>
2936 <entry><literal>WIN1251</literal></entry>
2937 </row>
2938 <row>
2939 <entry><literal>iso_8859_5_to_windows_866</literal></entry>
2940 <entry><literal>ISO_8859_5</literal></entry>
2941 <entry><literal>WIN866</literal></entry>
2942 </row>
2943 <row>
2944 <entry><literal>iso_8859_6_to_utf8</literal></entry>
2945 <entry><literal>ISO_8859_6</literal></entry>
2946 <entry><literal>UTF8</literal></entry>
2947 </row>
2948 <row>
2949 <entry><literal>iso_8859_7_to_utf8</literal></entry>
2950 <entry><literal>ISO_8859_7</literal></entry>
2951 <entry><literal>UTF8</literal></entry>
2952 </row>
2953 <row>
2954 <entry><literal>iso_8859_8_to_utf8</literal></entry>
2955 <entry><literal>ISO_8859_8</literal></entry>
2956 <entry><literal>UTF8</literal></entry>
2957 </row>
2958 <row>
2959 <entry><literal>iso_8859_9_to_utf8</literal></entry>
2960 <entry><literal>LATIN5</literal></entry>
2961 <entry><literal>UTF8</literal></entry>
2962 </row>
2963 <row>
2964 <entry><literal>johab_to_utf8</literal></entry>
2965 <entry><literal>JOHAB</literal></entry>
2966 <entry><literal>UTF8</literal></entry>
2967 </row>
2968 <row>
2969 <entry><literal>koi8_r_to_iso_8859_5</literal></entry>
2970 <entry><literal>KOI8R</literal></entry>
2971 <entry><literal>ISO_8859_5</literal></entry>
2972 </row>
2973 <row>
2974 <entry><literal>koi8_r_to_mic</literal></entry>
2975 <entry><literal>KOI8R</literal></entry>
2976 <entry><literal>MULE_INTERNAL</literal></entry>
2977 </row>
2978 <row>
2979 <entry><literal>koi8_r_to_utf8</literal></entry>
2980 <entry><literal>KOI8R</literal></entry>
2981 <entry><literal>UTF8</literal></entry>
2982 </row>
2983 <row>
2984 <entry><literal>koi8_r_to_windows_1251</literal></entry>
2985 <entry><literal>KOI8R</literal></entry>
2986 <entry><literal>WIN1251</literal></entry>
2987 </row>
2988 <row>
2989 <entry><literal>koi8_r_to_windows_866</literal></entry>
2990 <entry><literal>KOI8R</literal></entry>
2991 <entry><literal>WIN866</literal></entry>
2992 </row>
2993 <row>
2994 <entry><literal>koi8_u_to_utf8</literal></entry>
2995 <entry><literal>KOI8U</literal></entry>
2996 <entry><literal>UTF8</literal></entry>
2997 </row>
2998 <row>
2999 <entry><literal>mic_to_big5</literal></entry>
3000 <entry><literal>MULE_INTERNAL</literal></entry>
3001 <entry><literal>BIG5</literal></entry>
3002 </row>
3003 <row>
3004 <entry><literal>mic_to_euc_cn</literal></entry>
3005 <entry><literal>MULE_INTERNAL</literal></entry>
3006 <entry><literal>EUC_CN</literal></entry>
3007 </row>
3008 <row>
3009 <entry><literal>mic_to_euc_jp</literal></entry>
3010 <entry><literal>MULE_INTERNAL</literal></entry>
3011 <entry><literal>EUC_JP</literal></entry>
3012 </row>
3013 <row>
3014 <entry><literal>mic_to_euc_kr</literal></entry>
3015 <entry><literal>MULE_INTERNAL</literal></entry>
3016 <entry><literal>EUC_KR</literal></entry>
3017 </row>
3018 <row>
3019 <entry><literal>mic_to_euc_tw</literal></entry>
3020 <entry><literal>MULE_INTERNAL</literal></entry>
3021 <entry><literal>EUC_TW</literal></entry>
3022 </row>
3023 <row>
3024 <entry><literal>mic_to_iso_8859_1</literal></entry>
3025 <entry><literal>MULE_INTERNAL</literal></entry>
3026 <entry><literal>LATIN1</literal></entry>
3027 </row>
3028 <row>
3029 <entry><literal>mic_to_iso_8859_2</literal></entry>
3030 <entry><literal>MULE_INTERNAL</literal></entry>
3031 <entry><literal>LATIN2</literal></entry>
3032 </row>
3033 <row>
3034 <entry><literal>mic_to_iso_8859_3</literal></entry>
3035 <entry><literal>MULE_INTERNAL</literal></entry>
3036 <entry><literal>LATIN3</literal></entry>
3037 </row>
3038 <row>
3039 <entry><literal>mic_to_iso_8859_4</literal></entry>
3040 <entry><literal>MULE_INTERNAL</literal></entry>
3041 <entry><literal>LATIN4</literal></entry>
3042 </row>
3043 <row>
3044 <entry><literal>mic_to_iso_8859_5</literal></entry>
3045 <entry><literal>MULE_INTERNAL</literal></entry>
3046 <entry><literal>ISO_8859_5</literal></entry>
3047 </row>
3048 <row>
3049 <entry><literal>mic_to_koi8_r</literal></entry>
3050 <entry><literal>MULE_INTERNAL</literal></entry>
3051 <entry><literal>KOI8R</literal></entry>
3052 </row>
3053 <row>
3054 <entry><literal>mic_to_sjis</literal></entry>
3055 <entry><literal>MULE_INTERNAL</literal></entry>
3056 <entry><literal>SJIS</literal></entry>
3057 </row>
3058 <row>
3059 <entry><literal>mic_to_windows_1250</literal></entry>
3060 <entry><literal>MULE_INTERNAL</literal></entry>
3061 <entry><literal>WIN1250</literal></entry>
3062 </row>
3063 <row>
3064 <entry><literal>mic_to_windows_1251</literal></entry>
3065 <entry><literal>MULE_INTERNAL</literal></entry>
3066 <entry><literal>WIN1251</literal></entry>
3067 </row>
3068 <row>
3069 <entry><literal>mic_to_windows_866</literal></entry>
3070 <entry><literal>MULE_INTERNAL</literal></entry>
3071 <entry><literal>WIN866</literal></entry>
3072 </row>
3073 <row>
3074 <entry><literal>sjis_to_euc_jp</literal></entry>
3075 <entry><literal>SJIS</literal></entry>
3076 <entry><literal>EUC_JP</literal></entry>
3077 </row>
3078 <row>
3079 <entry><literal>sjis_to_mic</literal></entry>
3080 <entry><literal>SJIS</literal></entry>
3081 <entry><literal>MULE_INTERNAL</literal></entry>
3082 </row>
3083 <row>
3084 <entry><literal>sjis_to_utf8</literal></entry>
3085 <entry><literal>SJIS</literal></entry>
3086 <entry><literal>UTF8</literal></entry>
3087 </row>
3088 <row>
3089 <entry><literal>windows_1258_to_utf8</literal></entry>
3090 <entry><literal>WIN1258</literal></entry>
3091 <entry><literal>UTF8</literal></entry>
3092 </row>
3093 <row>
3094 <entry><literal>uhc_to_utf8</literal></entry>
3095 <entry><literal>UHC</literal></entry>
3096 <entry><literal>UTF8</literal></entry>
3097 </row>
3098 <row>
3099 <entry><literal>utf8_to_big5</literal></entry>
3100 <entry><literal>UTF8</literal></entry>
3101 <entry><literal>BIG5</literal></entry>
3102 </row>
3103 <row>
3104 <entry><literal>utf8_to_euc_cn</literal></entry>
3105 <entry><literal>UTF8</literal></entry>
3106 <entry><literal>EUC_CN</literal></entry>
3107 </row>
3108 <row>
3109 <entry><literal>utf8_to_euc_jp</literal></entry>
3110 <entry><literal>UTF8</literal></entry>
3111 <entry><literal>EUC_JP</literal></entry>
3112 </row>
3113 <row>
3114 <entry><literal>utf8_to_euc_kr</literal></entry>
3115 <entry><literal>UTF8</literal></entry>
3116 <entry><literal>EUC_KR</literal></entry>
3117 </row>
3118 <row>
3119 <entry><literal>utf8_to_euc_tw</literal></entry>
3120 <entry><literal>UTF8</literal></entry>
3121 <entry><literal>EUC_TW</literal></entry>
3122 </row>
3123 <row>
3124 <entry><literal>utf8_to_gb18030</literal></entry>
3125 <entry><literal>UTF8</literal></entry>
3126 <entry><literal>GB18030</literal></entry>
3127 </row>
3128 <row>
3129 <entry><literal>utf8_to_gbk</literal></entry>
3130 <entry><literal>UTF8</literal></entry>
3131 <entry><literal>GBK</literal></entry>
3132 </row>
3133 <row>
3134 <entry><literal>utf8_to_iso_8859_1</literal></entry>
3135 <entry><literal>UTF8</literal></entry>
3136 <entry><literal>LATIN1</literal></entry>
3137 </row>
3138 <row>
3139 <entry><literal>utf8_to_iso_8859_10</literal></entry>
3140 <entry><literal>UTF8</literal></entry>
3141 <entry><literal>LATIN6</literal></entry>
3142 </row>
3143 <row>
3144 <entry><literal>utf8_to_iso_8859_13</literal></entry>
3145 <entry><literal>UTF8</literal></entry>
3146 <entry><literal>LATIN7</literal></entry>
3147 </row>
3148 <row>
3149 <entry><literal>utf8_to_iso_8859_14</literal></entry>
3150 <entry><literal>UTF8</literal></entry>
3151 <entry><literal>LATIN8</literal></entry>
3152 </row>
3153 <row>
3154 <entry><literal>utf8_to_iso_8859_15</literal></entry>
3155 <entry><literal>UTF8</literal></entry>
3156 <entry><literal>LATIN9</literal></entry>
3157 </row>
3158 <row>
3159 <entry><literal>utf8_to_iso_8859_16</literal></entry>
3160 <entry><literal>UTF8</literal></entry>
3161 <entry><literal>LATIN10</literal></entry>
3162 </row>
3163 <row>
3164 <entry><literal>utf8_to_iso_8859_2</literal></entry>
3165 <entry><literal>UTF8</literal></entry>
3166 <entry><literal>LATIN2</literal></entry>
3167 </row>
3168 <row>
3169 <entry><literal>utf8_to_iso_8859_3</literal></entry>
3170 <entry><literal>UTF8</literal></entry>
3171 <entry><literal>LATIN3</literal></entry>
3172 </row>
3173 <row>
3174 <entry><literal>utf8_to_iso_8859_4</literal></entry>
3175 <entry><literal>UTF8</literal></entry>
3176 <entry><literal>LATIN4</literal></entry>
3177 </row>
3178 <row>
3179 <entry><literal>utf8_to_iso_8859_5</literal></entry>
3180 <entry><literal>UTF8</literal></entry>
3181 <entry><literal>ISO_8859_5</literal></entry>
3182 </row>
3183 <row>
3184 <entry><literal>utf8_to_iso_8859_6</literal></entry>
3185 <entry><literal>UTF8</literal></entry>
3186 <entry><literal>ISO_8859_6</literal></entry>
3187 </row>
3188 <row>
3189 <entry><literal>utf8_to_iso_8859_7</literal></entry>
3190 <entry><literal>UTF8</literal></entry>
3191 <entry><literal>ISO_8859_7</literal></entry>
3192 </row>
3193 <row>
3194 <entry><literal>utf8_to_iso_8859_8</literal></entry>
3195 <entry><literal>UTF8</literal></entry>
3196 <entry><literal>ISO_8859_8</literal></entry>
3197 </row>
3198 <row>
3199 <entry><literal>utf8_to_iso_8859_9</literal></entry>
3200 <entry><literal>UTF8</literal></entry>
3201 <entry><literal>LATIN5</literal></entry>
3202 </row>
3203 <row>
3204 <entry><literal>utf8_to_johab</literal></entry>
3205 <entry><literal>UTF8</literal></entry>
3206 <entry><literal>JOHAB</literal></entry>
3207 </row>
3208 <row>
3209 <entry><literal>utf8_to_koi8_r</literal></entry>
3210 <entry><literal>UTF8</literal></entry>
3211 <entry><literal>KOI8R</literal></entry>
3212 </row>
3213 <row>
3214 <entry><literal>utf8_to_koi8_u</literal></entry>
3215 <entry><literal>UTF8</literal></entry>
3216 <entry><literal>KOI8U</literal></entry>
3217 </row>
3218 <row>
3219 <entry><literal>utf8_to_sjis</literal></entry>
3220 <entry><literal>UTF8</literal></entry>
3221 <entry><literal>SJIS</literal></entry>
3222 </row>
3223 <row>
3224 <entry><literal>utf8_to_windows_1258</literal></entry>
3225 <entry><literal>UTF8</literal></entry>
3226 <entry><literal>WIN1258</literal></entry>
3227 </row>
3228 <row>
3229 <entry><literal>utf8_to_uhc</literal></entry>
3230 <entry><literal>UTF8</literal></entry>
3231 <entry><literal>UHC</literal></entry>
3232 </row>
3233 <row>
3234 <entry><literal>utf8_to_windows_1250</literal></entry>
3235 <entry><literal>UTF8</literal></entry>
3236 <entry><literal>WIN1250</literal></entry>
3237 </row>
3238 <row>
3239 <entry><literal>utf8_to_windows_1251</literal></entry>
3240 <entry><literal>UTF8</literal></entry>
3241 <entry><literal>WIN1251</literal></entry>
3242 </row>
3243 <row>
3244 <entry><literal>utf8_to_windows_1252</literal></entry>
3245 <entry><literal>UTF8</literal></entry>
3246 <entry><literal>WIN1252</literal></entry>
3247 </row>
3248 <row>
3249 <entry><literal>utf8_to_windows_1253</literal></entry>
3250 <entry><literal>UTF8</literal></entry>
3251 <entry><literal>WIN1253</literal></entry>
3252 </row>
3253 <row>
3254 <entry><literal>utf8_to_windows_1254</literal></entry>
3255 <entry><literal>UTF8</literal></entry>
3256 <entry><literal>WIN1254</literal></entry>
3257 </row>
3258 <row>
3259 <entry><literal>utf8_to_windows_1255</literal></entry>
3260 <entry><literal>UTF8</literal></entry>
3261 <entry><literal>WIN1255</literal></entry>
3262 </row>
3263 <row>
3264 <entry><literal>utf8_to_windows_1256</literal></entry>
3265 <entry><literal>UTF8</literal></entry>
3266 <entry><literal>WIN1256</literal></entry>
3267 </row>
3268 <row>
3269 <entry><literal>utf8_to_windows_1257</literal></entry>
3270 <entry><literal>UTF8</literal></entry>
3271 <entry><literal>WIN1257</literal></entry>
3272 </row>
3273 <row>
3274 <entry><literal>utf8_to_windows_866</literal></entry>
3275 <entry><literal>UTF8</literal></entry>
3276 <entry><literal>WIN866</literal></entry>
3277 </row>
3278 <row>
3279 <entry><literal>utf8_to_windows_874</literal></entry>
3280 <entry><literal>UTF8</literal></entry>
3281 <entry><literal>WIN874</literal></entry>
3282 </row>
3283 <row>
3284 <entry><literal>windows_1250_to_iso_8859_2</literal></entry>
3285 <entry><literal>WIN1250</literal></entry>
3286 <entry><literal>LATIN2</literal></entry>
3287 </row>
3288 <row>
3289 <entry><literal>windows_1250_to_mic</literal></entry>
3290 <entry><literal>WIN1250</literal></entry>
3291 <entry><literal>MULE_INTERNAL</literal></entry>
3292 </row>
3293 <row>
3294 <entry><literal>windows_1250_to_utf8</literal></entry>
3295 <entry><literal>WIN1250</literal></entry>
3296 <entry><literal>UTF8</literal></entry>
3297 </row>
3298 <row>
3299 <entry><literal>windows_1251_to_iso_8859_5</literal></entry>
3300 <entry><literal>WIN1251</literal></entry>
3301 <entry><literal>ISO_8859_5</literal></entry>
3302 </row>
3303 <row>
3304 <entry><literal>windows_1251_to_koi8_r</literal></entry>
3305 <entry><literal>WIN1251</literal></entry>
3306 <entry><literal>KOI8R</literal></entry>
3307 </row>
3308 <row>
3309 <entry><literal>windows_1251_to_mic</literal></entry>
3310 <entry><literal>WIN1251</literal></entry>
3311 <entry><literal>MULE_INTERNAL</literal></entry>
3312 </row>
3313 <row>
3314 <entry><literal>windows_1251_to_utf8</literal></entry>
3315 <entry><literal>WIN1251</literal></entry>
3316 <entry><literal>UTF8</literal></entry>
3317 </row>
3318 <row>
3319 <entry><literal>windows_1251_to_windows_866</literal></entry>
3320 <entry><literal>WIN1251</literal></entry>
3321 <entry><literal>WIN866</literal></entry>
3322 </row>
3323 <row>
3324 <entry><literal>windows_1252_to_utf8</literal></entry>
3325 <entry><literal>WIN1252</literal></entry>
3326 <entry><literal>UTF8</literal></entry>
3327 </row>
3328 <row>
3329 <entry><literal>windows_1256_to_utf8</literal></entry>
3330 <entry><literal>WIN1256</literal></entry>
3331 <entry><literal>UTF8</literal></entry>
3332 </row>
3333 <row>
3334 <entry><literal>windows_866_to_iso_8859_5</literal></entry>
3335 <entry><literal>WIN866</literal></entry>
3336 <entry><literal>ISO_8859_5</literal></entry>
3337 </row>
3338 <row>
3339 <entry><literal>windows_866_to_koi8_r</literal></entry>
3340 <entry><literal>WIN866</literal></entry>
3341 <entry><literal>KOI8R</literal></entry>
3342 </row>
3343 <row>
3344 <entry><literal>windows_866_to_mic</literal></entry>
3345 <entry><literal>WIN866</literal></entry>
3346 <entry><literal>MULE_INTERNAL</literal></entry>
3347 </row>
3348 <row>
3349 <entry><literal>windows_866_to_utf8</literal></entry>
3350 <entry><literal>WIN866</literal></entry>
3351 <entry><literal>UTF8</literal></entry>
3352 </row>
3353 <row>
3354 <entry><literal>windows_866_to_windows_1251</literal></entry>
3355 <entry><literal>WIN866</literal></entry>
3356 <entry><literal>WIN</literal></entry>
3357 </row>
3358 <row>
3359 <entry><literal>windows_874_to_utf8</literal></entry>
3360 <entry><literal>WIN874</literal></entry>
3361 <entry><literal>UTF8</literal></entry>
3362 </row>
3363 <row>
3364 <entry><literal>euc_jis_2004_to_utf8</literal></entry>
3365 <entry><literal>EUC_JIS_2004</literal></entry>
3366 <entry><literal>UTF8</literal></entry>
3367 </row>
3368 <row>
3369 <entry><literal>utf8_to_euc_jis_2004</literal></entry>
3370 <entry><literal>UTF8</literal></entry>
3371 <entry><literal>EUC_JIS_2004</literal></entry>
3372 </row>
3373 <row>
3374 <entry><literal>shift_jis_2004_to_utf8</literal></entry>
3375 <entry><literal>SHIFT_JIS_2004</literal></entry>
3376 <entry><literal>UTF8</literal></entry>
3377 </row>
3378 <row>
3379 <entry><literal>utf8_to_shift_jis_2004</literal></entry>
3380 <entry><literal>UTF8</literal></entry>
3381 <entry><literal>SHIFT_JIS_2004</literal></entry>
3382 </row>
3383 <row>
3384 <entry><literal>euc_jis_2004_to_shift_jis_2004</literal></entry>
3385 <entry><literal>EUC_JIS_2004</literal></entry>
3386 <entry><literal>SHIFT_JIS_2004</literal></entry>
3387 </row>
3388 <row>
3389 <entry><literal>shift_jis_2004_to_euc_jis_2004</literal></entry>
3390 <entry><literal>SHIFT_JIS_2004</literal></entry>
3391 <entry><literal>EUC_JIS_2004</literal></entry>
3392 </row>
3393 </tbody>
3394 </tgroup>
3395 </table>
3396 </sect2>
3397
3398 <sect2 id="multibyte-further-reading">
3399 <title>Further Reading</title>
3400
3401 <para>
3402 These are good sources to start learning about various kinds of encoding
3403 systems.
3404
3405 <variablelist>
3406 <varlistentry>
3407 <term><citetitle>CJKV Information Processing: Chinese, Japanese, Korean &amp; Vietnamese Computing</citetitle></term>
3408
3409 <listitem>
3410 <para>
3411 Contains detailed explanations of <literal>EUC_JP</literal>,
3412 <literal>EUC_CN</literal>, <literal>EUC_KR</literal>,
3413 <literal>EUC_TW</literal>.
3414 </para>
3415 </listitem>
3416 </varlistentry>
3417
3418 <varlistentry>
3419 <term><ulink url="https://www.unicode.org/"></ulink></term>
3420
3421 <listitem>
3422 <para>
3423 The web site of the Unicode Consortium.
3424 </para>
3425 </listitem>
3426 </varlistentry>
3427
3428 <varlistentry>
3429 <term><ulink url="https://datatracker.ietf.org/doc/html/rfc3629">RFC 3629</ulink></term>
3430
3431 <listitem>
3432 <para>
3433 <acronym>UTF</acronym>-8 (8-bit UCS/Unicode Transformation
3434 Format) is defined here.
3435 </para>
3436 </listitem>
3437 </varlistentry>
3438 </variablelist>
3439 </para>
3440 </sect2>
3441
3442 </sect1>
3443
3444 </chapter>