1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688
|
<!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 9.1.15 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="Localization"
HREF="charset.html"><LINK
REL="PREVIOUS"
TITLE="Localization"
HREF="charset.html"><LINK
REL="NEXT"
TITLE="Collation Support"
HREF="collation.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="2015-02-02T21:03:01"></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"
><A
HREF="index.html"
>PostgreSQL 9.1.15 Documentation</A
></TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
TITLE="Localization"
HREF="charset.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="charset.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
>Chapter 22. Localization</TD
><TD
WIDTH="20%"
ALIGN="right"
VALIGN="top"
><A
TITLE="Collation Support"
HREF="collation.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
><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="AEN31544"
>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 for Unix systems sets the locale to Swedish
(<TT
CLASS="LITERAL"
>sv</TT
>) as spoken
in Sweden (<TT
CLASS="LITERAL"
>SE</TT
>). Other possibilities might include
<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 used for a
locale then the specifications can take the form
<TT
CLASS="REPLACEABLE"
><I
>language_territory.codeset</I
></TT
>. For example,
<TT
CLASS="LITERAL"
>fr_BE.UTF-8</TT
> represents the French language (fr) as
spoken in Belgium (BE), with a <ACRONYM
CLASS="ACRONYM"
>UTF-8</ACRONYM
> character set
encoding.
</P
><P
> What locales are available on your
system under what names depends on what was provided by the operating
system vendor and what was installed. On most Unix systems, the command
<TT
CLASS="LITERAL"
>locale -a</TT
> will provide a list of available locales.
Windows uses more verbose locale names, such as <TT
CLASS="LITERAL"
>German_Germany</TT
>
or <TT
CLASS="LITERAL"
>Swedish_Sweden.1252</TT
>, but the principles are the same.
</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 certain
aspects of the localization rules:
<DIV
CLASS="INFORMALTABLE"
><P
></P
><A
NAME="AEN31565"
></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 name <TT
CLASS="LITERAL"
>C</TT
>, or equivalently
<TT
CLASS="LITERAL"
>POSIX</TT
>.
</P
><P
> Some locale categories must have their values
fixed when the database is created. You can use different settings
for different databases, but once a database is created, you cannot
change them for that database anymore. <TT
CLASS="LITERAL"
>LC_COLLATE</TT
>
and <TT
CLASS="LITERAL"
>LC_CTYPE</TT
> are these categories. They affect
the sort order of indexes, so they must be kept fixed, or indexes on
text columns would become corrupt.
(But you can alleviate this restriction using collations, as discussed
in <A
HREF="collation.html"
>Section 22.2</A
>.)
The default values for these
categories are determined when <TT
CLASS="COMMAND"
>initdb</TT
> is run, and
those values are used when new databases are created, unless
specified otherwise in the <TT
CLASS="COMMAND"
>CREATE DATABASE</TT
> command.
</P
><P
> The other locale categories can be changed whenever desired
by setting the server configuration parameters
that have the same name as the locale categories (see <A
HREF="runtime-config-client.html#RUNTIME-CONFIG-CLIENT-FORMAT"
>Section 18.11.2</A
> for details). The values
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 remove 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
>
(or 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
>.
</P
></BLOCKQUOTE
></DIV
><P
> To enable messages to be translated to the user's preferred language,
<ACRONYM
CLASS="ACRONYM"
>NLS</ACRONYM
> must have been selected at build time
(<TT
CLASS="LITERAL"
>configure --enable-nls</TT
>). All other locale support is
built in automatically.
</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN31621"
>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
> or the standard
comparison operators on textual data
</P
></LI
><LI
><P
> The <CODE
CLASS="FUNCTION"
>upper</CODE
>, <CODE
CLASS="FUNCTION"
>lower</CODE
>, and <CODE
CLASS="FUNCTION"
>initcap</CODE
>
functions
</P
></LI
><LI
><P
> Pattern matching operators (<TT
CLASS="LITERAL"
>LIKE</TT
>, <TT
CLASS="LITERAL"
>SIMILAR TO</TT
>,
and POSIX-style regular expressions); locales affect both case
insensitive matching and the classification of characters by
character-class regular expressions
</P
></LI
><LI
><P
> The <CODE
CLASS="FUNCTION"
>to_char</CODE
> family of functions
</P
></LI
><LI
><P
> The ability to use indexes with <TT
CLASS="LITERAL"
>LIKE</TT
> clauses
</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. Another approach is to create indexes using
the <TT
CLASS="LITERAL"
>C</TT
> collation, as discussed in
<A
HREF="collation.html"
>Section 22.2</A
>.
</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN31672"
>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. The <TT
CLASS="ENVAR"
>LC_COLLATE</TT
> and <TT
CLASS="ENVAR"
>LC_CTYPE</TT
>
settings are determined when a database is created, and cannot be
changed except by creating a new database. 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 48</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="collation.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"
>Collation Support</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>
|