Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > media > main-testing > by-pkgid > bab02a23fa9f3df8d66a9a3231b50245 > files > 362

postgresql8.3-docs-8.3.6-2mdv2008.1.x86_64.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Locale Support</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 8.3.6 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="Localization"
HREF="charset.html"><LINK
REL="PREVIOUS"
TITLE="Localization"
HREF="charset.html"><LINK
REL="NEXT"
TITLE="Character Set Support"
HREF="multibyte.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2009-02-03T04:34:16"></HEAD
><BODY
CLASS="SECT1"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="5"
ALIGN="center"
VALIGN="bottom"
>PostgreSQL 8.3.6 Documentation</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="charset.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="charset.html"
>Fast Backward</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
>Chapter 22. Localization</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="top"
><A
HREF="charset.html"
>Fast Forward</A
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="top"
><A
HREF="multibyte.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="LOCALE"
>22.1. Locale Support</A
></H1
><A
NAME="AEN26887"
></A
><P
>   <I
CLASS="FIRSTTERM"
>Locale</I
> support refers to an application respecting
   cultural preferences regarding alphabets, sorting, number
   formatting, etc.  <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> uses the standard ISO
   C and <ACRONYM
CLASS="ACRONYM"
>POSIX</ACRONYM
> locale facilities provided by the server operating
   system.  For additional information refer to the documentation of your
   system.
  </P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN26893"
>22.1.1. Overview</A
></H2
><P
>    Locale support is automatically initialized when a database
    cluster is created using <TT
CLASS="COMMAND"
>initdb</TT
>.
    <TT
CLASS="COMMAND"
>initdb</TT
> will initialize the database cluster
    with the locale setting of its execution environment by default,
    so if your system is already set to use the locale that you want
    in your database cluster then there is nothing else you need to
    do.  If you want to use a different locale (or you are not sure
    which locale your system is set to), you can instruct
    <TT
CLASS="COMMAND"
>initdb</TT
> exactly which locale to use by
    specifying the <TT
CLASS="OPTION"
>--locale</TT
> option. For example:
</P><PRE
CLASS="SCREEN"
>initdb --locale=sv_SE</PRE
><P>
   </P
><P
>    This example sets the locale to Swedish (<TT
CLASS="LITERAL"
>sv</TT
>) as spoken
    in Sweden (<TT
CLASS="LITERAL"
>SE</TT
>).  Other possibilities might be
    <TT
CLASS="LITERAL"
>en_US</TT
> (U.S. English) and <TT
CLASS="LITERAL"
>fr_CA</TT
> (French
    Canadian).  If more than one character set can be useful for a
    locale then the specifications look like this:
    <TT
CLASS="LITERAL"
>cs_CZ.ISO8859-2</TT
>. What locales are available under what
    names on your system depends on what was provided by the operating
    system vendor and what was installed.  (On most systems, the command
    <TT
CLASS="LITERAL"
>locale -a</TT
> will provide a list of available locales.)
   </P
><P
>    Occasionally it is useful to mix rules from several locales, e.g.,
    use English collation rules but Spanish messages.  To support that, a
    set of locale subcategories exist that control only a certain
    aspect of the localization rules:

    <DIV
CLASS="INFORMALTABLE"
><P
></P
><A
NAME="AEN26909"
></A
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><TBODY
><TR
><TD
><TT
CLASS="ENVAR"
>LC_COLLATE</TT
></TD
><TD
>String sort order</TD
></TR
><TR
><TD
><TT
CLASS="ENVAR"
>LC_CTYPE</TT
></TD
><TD
>Character classification (What is a letter? Its upper-case equivalent?)</TD
></TR
><TR
><TD
><TT
CLASS="ENVAR"
>LC_MESSAGES</TT
></TD
><TD
>Language of messages</TD
></TR
><TR
><TD
><TT
CLASS="ENVAR"
>LC_MONETARY</TT
></TD
><TD
>Formatting of currency amounts</TD
></TR
><TR
><TD
><TT
CLASS="ENVAR"
>LC_NUMERIC</TT
></TD
><TD
>Formatting of numbers</TD
></TR
><TR
><TD
><TT
CLASS="ENVAR"
>LC_TIME</TT
></TD
><TD
>Formatting of dates and times</TD
></TR
></TBODY
></TABLE
><P
></P
></DIV
>

    The category names translate into names of
    <TT
CLASS="COMMAND"
>initdb</TT
> options to override the locale choice
    for a specific category.  For instance, to set the locale to
    French Canadian, but use U.S. rules for formatting currency, use
    <TT
CLASS="LITERAL"
>initdb --locale=fr_CA --lc-monetary=en_US</TT
>.
   </P
><P
>    If you want the system to behave as if it had no locale support,
    use the special locale <TT
CLASS="LITERAL"
>C</TT
> or <TT
CLASS="LITERAL"
>POSIX</TT
>.
   </P
><P
>    The nature of some locale categories is that their value has to be
    fixed for the lifetime of a database cluster.  That is, once
    <TT
CLASS="COMMAND"
>initdb</TT
> has run, you cannot change them anymore.
    <TT
CLASS="LITERAL"
>LC_COLLATE</TT
> and <TT
CLASS="LITERAL"
>LC_CTYPE</TT
> are
    those categories.  They affect the sort order of indexes, so they
    must be kept fixed, or indexes on text columns will become corrupt.
    <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> enforces this by recording
    the values of <TT
CLASS="ENVAR"
>LC_COLLATE</TT
> and <TT
CLASS="ENVAR"
>LC_CTYPE</TT
> that are
    seen by <TT
CLASS="COMMAND"
>initdb</TT
>.  The server automatically adopts
    those two values when it is started.
   </P
><P
>    The other locale categories can be changed as desired whenever the
    server is running by setting the run-time configuration variables
    that have the same name as the locale categories (see <A
HREF="runtime-config-client.html#RUNTIME-CONFIG-CLIENT-FORMAT"
>Section 18.10.2</A
> for details).  The defaults that are
    chosen by <TT
CLASS="COMMAND"
>initdb</TT
> are actually only written into
    the configuration file <TT
CLASS="FILENAME"
>postgresql.conf</TT
> to
    serve as defaults when the server is started.  If you delete these
    assignments from <TT
CLASS="FILENAME"
>postgresql.conf</TT
> then the
    server will inherit the settings from its execution environment.
   </P
><P
>    Note that the locale behavior of the server is determined by the
    environment variables seen by the server, not by the environment
    of any client.  Therefore, be careful to configure the correct locale settings
    before starting the server.  A consequence of this is that if
    client and server are set up in different locales, messages might
    appear in different languages depending on where they originated.
   </P
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
>     When we speak of inheriting the locale from the execution
     environment, this means the following on most operating systems:
     For a given locale category, say the collation, the following
     environment variables are consulted in this order until one is
     found to be set: <TT
CLASS="ENVAR"
>LC_ALL</TT
>, <TT
CLASS="ENVAR"
>LC_COLLATE</TT
>
     (the variable corresponding to the respective category),
     <TT
CLASS="ENVAR"
>LANG</TT
>.  If none of these environment variables are
     set then the locale defaults to <TT
CLASS="LITERAL"
>C</TT
>.
    </P
><P
>     Some message localization libraries also look at the environment
     variable <TT
CLASS="ENVAR"
>LANGUAGE</TT
> which overrides all other locale
     settings for the purpose of setting the language of messages.  If
     in doubt, please refer to the documentation of your operating
     system, in particular the documentation about
     <SPAN
CLASS="APPLICATION"
>gettext</SPAN
>, for more information.
    </P
></BLOCKQUOTE
></DIV
><P
>    To enable messages to be translated to the user's preferred language,
    <ACRONYM
CLASS="ACRONYM"
>NLS</ACRONYM
> must have been enabled at build time.  This
    choice is independent of the other locale support.
   </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN26966"
>22.1.2. Behavior</A
></H2
><P
>    The locale settings influence the following SQL features:

    <P
></P
></P><UL
><LI
><P
>       Sort order in queries using <TT
CLASS="LITERAL"
>ORDER BY</TT
> on textual data
       <A
NAME="AEN26973"
></A
>
      </P
></LI
><LI
><P
>       The ability to use indexes with <TT
CLASS="LITERAL"
>LIKE</TT
> clauses
       <A
NAME="AEN26979"
></A
>
      </P
></LI
><LI
><P
>       The <CODE
CLASS="FUNCTION"
>upper</CODE
>,  <CODE
CLASS="FUNCTION"
>lower</CODE
>,  and <CODE
CLASS="FUNCTION"
>initcap</CODE
>
       functions
       <A
NAME="AEN26987"
></A
>
       <A
NAME="AEN26990"
></A
>
      </P
></LI
><LI
><P
>       The <CODE
CLASS="FUNCTION"
>to_char</CODE
> family of functions
       <A
NAME="AEN26996"
></A
>
      </P
></LI
></UL
><P>
   </P
><P
>    The drawback of using locales other than <TT
CLASS="LITERAL"
>C</TT
> or
    <TT
CLASS="LITERAL"
>POSIX</TT
> in <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> is its performance
    impact. It slows character handling and prevents ordinary indexes
    from being used by <TT
CLASS="LITERAL"
>LIKE</TT
>. For this reason use locales
    only if you actually need them.
   </P
><P
>    As a workaround to allow <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> to use indexes
    with <TT
CLASS="LITERAL"
>LIKE</TT
> clauses under a non-C locale, several custom
    operator classes exist. These allow the creation of an index that
    performs a strict character-by-character comparison, ignoring
    locale comparison rules. Refer to <A
HREF="indexes-opclass.html"
>Section 11.9</A
>
    for more information.
   </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN27008"
>22.1.3. Problems</A
></H2
><P
>    If locale support doesn't work according to the explanation above,
    check that the locale support in your operating system is
    correctly configured.  To check what locales are installed on your
    system, you can use the command <TT
CLASS="LITERAL"
>locale -a</TT
> if
    your operating system provides it.
   </P
><P
>    Check that <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> is actually using the locale
    that you think it is.  <TT
CLASS="ENVAR"
>LC_COLLATE</TT
> and <TT
CLASS="ENVAR"
>LC_CTYPE</TT
>
    settings are determined at <TT
CLASS="COMMAND"
>initdb</TT
> time and cannot be
    changed without repeating <TT
CLASS="COMMAND"
>initdb</TT
>.  Other locale
    settings including <TT
CLASS="ENVAR"
>LC_MESSAGES</TT
> and <TT
CLASS="ENVAR"
>LC_MONETARY</TT
>
    are initially determined by the environment the server is started
    in, but can be changed on-the-fly.  You can check the active locale
    settings using the <TT
CLASS="COMMAND"
>SHOW</TT
> command.
   </P
><P
>    The directory <TT
CLASS="FILENAME"
>src/test/locale</TT
> in the source
    distribution contains a test suite for
    <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>'s locale support.
   </P
><P
>    Client applications that handle server-side errors by parsing the
    text of the error message will obviously have problems when the
    server's messages are in a different language.  Authors of such
    applications are advised to make use of the error code scheme
    instead.
   </P
><P
>    Maintaining catalogs of message translations requires the on-going
    efforts of many volunteers that want to see
    <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> speak their preferred language well.
    If messages in your language are currently not available or not fully
    translated, your assistance would be appreciated.  If you want to
    help, refer to <A
HREF="nls.html"
>Chapter 47</A
> or write to the developers'
    mailing list.
   </P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="charset.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="multibyte.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Localization</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="charset.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Character Set Support</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>