gooderp18绿色标准版
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

182 líneas
14KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>23.1. Locale Support</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="charset.html" title="Chapter 23. Localization" /><link rel="next" href="collation.html" title="23.2. Collation Support" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">23.1. Locale Support</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="charset.html" title="Chapter 23. Localization">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="charset.html" title="Chapter 23. Localization">Up</a></td><th width="60%" align="center">Chapter 23. Localization</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="collation.html" title="23.2. Collation Support">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="LOCALE"><div class="titlepage"><div><div><h2 class="title" style="clear: both">23.1. Locale Support</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="locale.html#id-1.6.10.3.4">23.1.1. Overview</a></span></dt><dt><span class="sect2"><a href="locale.html#id-1.6.10.3.5">23.1.2. Behavior</a></span></dt><dt><span class="sect2"><a href="locale.html#id-1.6.10.3.6">23.1.3. Problems</a></span></dt></dl></div><a id="id-1.6.10.3.2" class="indexterm"></a><p>
  3. <em class="firstterm">Locale</em> support refers to an application respecting
  4. cultural preferences regarding alphabets, sorting, number
  5. formatting, etc. <span class="productname">PostgreSQL</span> uses the standard ISO
  6. C and <acronym class="acronym">POSIX</acronym> locale facilities provided by the server operating
  7. system. For additional information refer to the documentation of your
  8. system.
  9. </p><div class="sect2" id="id-1.6.10.3.4"><div class="titlepage"><div><div><h3 class="title">23.1.1. Overview</h3></div></div></div><p>
  10. Locale support is automatically initialized when a database
  11. cluster is created using <code class="command">initdb</code>.
  12. <code class="command">initdb</code> will initialize the database cluster
  13. with the locale setting of its execution environment by default,
  14. so if your system is already set to use the locale that you want
  15. in your database cluster then there is nothing else you need to
  16. do. If you want to use a different locale (or you are not sure
  17. which locale your system is set to), you can instruct
  18. <code class="command">initdb</code> exactly which locale to use by
  19. specifying the <code class="option">--locale</code> option. For example:
  20. </p><pre class="screen">
  21. initdb --locale=sv_SE
  22. </pre><p>
  23. </p><p>
  24. This example for Unix systems sets the locale to Swedish
  25. (<code class="literal">sv</code>) as spoken
  26. in Sweden (<code class="literal">SE</code>). Other possibilities might include
  27. <code class="literal">en_US</code> (U.S. English) and <code class="literal">fr_CA</code> (French
  28. Canadian). If more than one character set can be used for a
  29. locale then the specifications can take the form
  30. <em class="replaceable"><code>language_territory.codeset</code></em>. For example,
  31. <code class="literal">fr_BE.UTF-8</code> represents the French language (fr) as
  32. spoken in Belgium (BE), with a <acronym class="acronym">UTF-8</acronym> character set
  33. encoding.
  34. </p><p>
  35. What locales are available on your
  36. system under what names depends on what was provided by the operating
  37. system vendor and what was installed. On most Unix systems, the command
  38. <code class="literal">locale -a</code> will provide a list of available locales.
  39. Windows uses more verbose locale names, such as <code class="literal">German_Germany</code>
  40. or <code class="literal">Swedish_Sweden.1252</code>, but the principles are the same.
  41. </p><p>
  42. Occasionally it is useful to mix rules from several locales, e.g.,
  43. use English collation rules but Spanish messages. To support that, a
  44. set of locale subcategories exist that control only certain
  45. aspects of the localization rules:
  46. </p><div class="informaltable"><table class="informaltable" border="1"><colgroup><col /><col /></colgroup><tbody><tr><td><code class="envar">LC_COLLATE</code></td><td>String sort order</td></tr><tr><td><code class="envar">LC_CTYPE</code></td><td>Character classification (What is a letter? Its upper-case equivalent?)</td></tr><tr><td><code class="envar">LC_MESSAGES</code></td><td>Language of messages</td></tr><tr><td><code class="envar">LC_MONETARY</code></td><td>Formatting of currency amounts</td></tr><tr><td><code class="envar">LC_NUMERIC</code></td><td>Formatting of numbers</td></tr><tr><td><code class="envar">LC_TIME</code></td><td>Formatting of dates and times</td></tr></tbody></table></div><p>
  47. The category names translate into names of
  48. <code class="command">initdb</code> options to override the locale choice
  49. for a specific category. For instance, to set the locale to
  50. French Canadian, but use U.S. rules for formatting currency, use
  51. <code class="literal">initdb --locale=fr_CA --lc-monetary=en_US</code>.
  52. </p><p>
  53. If you want the system to behave as if it had no locale support,
  54. use the special locale name <code class="literal">C</code>, or equivalently
  55. <code class="literal">POSIX</code>.
  56. </p><p>
  57. Some locale categories must have their values
  58. fixed when the database is created. You can use different settings
  59. for different databases, but once a database is created, you cannot
  60. change them for that database anymore. <code class="literal">LC_COLLATE</code>
  61. and <code class="literal">LC_CTYPE</code> are these categories. They affect
  62. the sort order of indexes, so they must be kept fixed, or indexes on
  63. text columns would become corrupt.
  64. (But you can alleviate this restriction using collations, as discussed
  65. in <a class="xref" href="collation.html" title="23.2. Collation Support">Section 23.2</a>.)
  66. The default values for these
  67. categories are determined when <code class="command">initdb</code> is run, and
  68. those values are used when new databases are created, unless
  69. specified otherwise in the <code class="command">CREATE DATABASE</code> command.
  70. </p><p>
  71. The other locale categories can be changed whenever desired
  72. by setting the server configuration parameters
  73. that have the same name as the locale categories (see <a class="xref" href="runtime-config-client.html#RUNTIME-CONFIG-CLIENT-FORMAT" title="19.11.2. Locale and Formatting">Section 19.11.2</a> for details). The values
  74. that are chosen by <code class="command">initdb</code> are actually only written
  75. into the configuration file <code class="filename">postgresql.conf</code> to
  76. serve as defaults when the server is started. If you remove these
  77. assignments from <code class="filename">postgresql.conf</code> then the
  78. server will inherit the settings from its execution environment.
  79. </p><p>
  80. Note that the locale behavior of the server is determined by the
  81. environment variables seen by the server, not by the environment
  82. of any client. Therefore, be careful to configure the correct locale settings
  83. before starting the server. A consequence of this is that if
  84. client and server are set up in different locales, messages might
  85. appear in different languages depending on where they originated.
  86. </p><div class="note"><h3 class="title">Note</h3><p>
  87. When we speak of inheriting the locale from the execution
  88. environment, this means the following on most operating systems:
  89. For a given locale category, say the collation, the following
  90. environment variables are consulted in this order until one is
  91. found to be set: <code class="envar">LC_ALL</code>, <code class="envar">LC_COLLATE</code>
  92. (or the variable corresponding to the respective category),
  93. <code class="envar">LANG</code>. If none of these environment variables are
  94. set then the locale defaults to <code class="literal">C</code>.
  95. </p><p>
  96. Some message localization libraries also look at the environment
  97. variable <code class="envar">LANGUAGE</code> which overrides all other locale
  98. settings for the purpose of setting the language of messages. If
  99. in doubt, please refer to the documentation of your operating
  100. system, in particular the documentation about
  101. <span class="application">gettext</span>.
  102. </p></div><p>
  103. To enable messages to be translated to the user's preferred language,
  104. <acronym class="acronym">NLS</acronym> must have been selected at build time
  105. (<code class="literal">configure --enable-nls</code>). All other locale support is
  106. built in automatically.
  107. </p></div><div class="sect2" id="id-1.6.10.3.5"><div class="titlepage"><div><div><h3 class="title">23.1.2. Behavior</h3></div></div></div><p>
  108. The locale settings influence the following SQL features:
  109. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  110. Sort order in queries using <code class="literal">ORDER BY</code> or the standard
  111. comparison operators on textual data
  112. <a id="id-1.6.10.3.5.2.1.1.1.2" class="indexterm"></a>
  113. </p></li><li class="listitem"><p>
  114. The <code class="function">upper</code>, <code class="function">lower</code>, and <code class="function">initcap</code>
  115. functions
  116. <a id="id-1.6.10.3.5.2.1.2.1.4" class="indexterm"></a>
  117. <a id="id-1.6.10.3.5.2.1.2.1.5" class="indexterm"></a>
  118. </p></li><li class="listitem"><p>
  119. Pattern matching operators (<code class="literal">LIKE</code>, <code class="literal">SIMILAR TO</code>,
  120. and POSIX-style regular expressions); locales affect both case
  121. insensitive matching and the classification of characters by
  122. character-class regular expressions
  123. <a id="id-1.6.10.3.5.2.1.3.1.3" class="indexterm"></a>
  124. <a id="id-1.6.10.3.5.2.1.3.1.4" class="indexterm"></a>
  125. </p></li><li class="listitem"><p>
  126. The <code class="function">to_char</code> family of functions
  127. <a id="id-1.6.10.3.5.2.1.4.1.2" class="indexterm"></a>
  128. </p></li><li class="listitem"><p>
  129. The ability to use indexes with <code class="literal">LIKE</code> clauses
  130. </p></li></ul></div><p>
  131. </p><p>
  132. The drawback of using locales other than <code class="literal">C</code> or
  133. <code class="literal">POSIX</code> in <span class="productname">PostgreSQL</span> is its performance
  134. impact. It slows character handling and prevents ordinary indexes
  135. from being used by <code class="literal">LIKE</code>. For this reason use locales
  136. only if you actually need them.
  137. </p><p>
  138. As a workaround to allow <span class="productname">PostgreSQL</span> to use indexes
  139. with <code class="literal">LIKE</code> clauses under a non-C locale, several custom
  140. operator classes exist. These allow the creation of an index that
  141. performs a strict character-by-character comparison, ignoring
  142. locale comparison rules. Refer to <a class="xref" href="indexes-opclass.html" title="11.10. Operator Classes and Operator Families">Section 11.10</a>
  143. for more information. Another approach is to create indexes using
  144. the <code class="literal">C</code> collation, as discussed in
  145. <a class="xref" href="collation.html" title="23.2. Collation Support">Section 23.2</a>.
  146. </p></div><div class="sect2" id="id-1.6.10.3.6"><div class="titlepage"><div><div><h3 class="title">23.1.3. Problems</h3></div></div></div><p>
  147. If locale support doesn't work according to the explanation above,
  148. check that the locale support in your operating system is
  149. correctly configured. To check what locales are installed on your
  150. system, you can use the command <code class="literal">locale -a</code> if
  151. your operating system provides it.
  152. </p><p>
  153. Check that <span class="productname">PostgreSQL</span> is actually using the locale
  154. that you think it is. The <code class="envar">LC_COLLATE</code> and <code class="envar">LC_CTYPE</code>
  155. settings are determined when a database is created, and cannot be
  156. changed except by creating a new database. Other locale
  157. settings including <code class="envar">LC_MESSAGES</code> and <code class="envar">LC_MONETARY</code>
  158. are initially determined by the environment the server is started
  159. in, but can be changed on-the-fly. You can check the active locale
  160. settings using the <code class="command">SHOW</code> command.
  161. </p><p>
  162. The directory <code class="filename">src/test/locale</code> in the source
  163. distribution contains a test suite for
  164. <span class="productname">PostgreSQL</span>'s locale support.
  165. </p><p>
  166. Client applications that handle server-side errors by parsing the
  167. text of the error message will obviously have problems when the
  168. server's messages are in a different language. Authors of such
  169. applications are advised to make use of the error code scheme
  170. instead.
  171. </p><p>
  172. Maintaining catalogs of message translations requires the on-going
  173. efforts of many volunteers that want to see
  174. <span class="productname">PostgreSQL</span> speak their preferred language well.
  175. If messages in your language are currently not available or not fully
  176. translated, your assistance would be appreciated. If you want to
  177. help, refer to <a class="xref" href="nls.html" title="Chapter 54. Native Language Support">Chapter 54</a> or write to the developers'
  178. mailing list.
  179. </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="charset.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="charset.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="collation.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 23. Localization </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 23.2. Collation Support</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1