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 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>21.2.Character Set Support</title>
<link rel="stylesheet" href="stylesheet.css" type="text/css">
<link rev="made" href="pgsql-docs@postgresql.org">
<meta name="generator" content="DocBook XSL Stylesheets V1.70.0">
<link rel="start" href="index.html" title="PostgreSQL 8.1.4 Documentation">
<link rel="up" href="charset.html" title="Chapter21.Localization">
<link rel="prev" href="charset.html" title="Chapter21.Localization">
<link rel="next" href="maintenance.html" title="Chapter22.Routine Database Maintenance Tasks">
<link rel="copyright" href="ln-legalnotice.html" title="Legal Notice">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="sect1" lang="en">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="multibyte"></a>21.2.Character Set Support</h2></div></div></div>
<a name="id663704"></a><p> The character set support in <span class="productname">PostgreSQL</span>
allows you to store text in a variety of character sets, including
single-byte character sets such as the ISO 8859 series and
multiple-byte character sets such as <acronym class="acronym">EUC</acronym> (Extended Unix
Code), UTF-8, and Mule internal code. All character sets can be
used transparently throughout the server. (If you use extension
functions from other sources, it depends on whether they wrote
their code correctly.) The default character set is selected while
initializing your <span class="productname">PostgreSQL</span> database
cluster using <code class="command">initdb</code>. It can be overridden when you
create a database using <code class="command">createdb</code> or by using the
SQL command <code class="command">CREATE DATABASE</code>. So you can have multiple
databases each with a different character set.
</p>
<div class="sect2" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="multibyte-charset-supported"></a>21.2.1.Supported Character Sets</h3></div></div></div>
<p> <a href="multibyte.html#charset-table" title="Table21.1.Server Character Sets">Table21.1, “Server Character Sets”</a> shows the character sets available
for use in the server.
</p>
<div class="table">
<a name="charset-table"></a><p class="title"><b>Table21.1.Server Character Sets</b></p>
<div class="table-contents"><table summary="Server Character Sets" border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>Name</th>
<th>Description</th>
<th>Language</th>
<th>Bytes/Char</th>
<th>Aliases</th>
</tr></thead>
<tbody>
<tr>
<td><code class="literal">BIG5</code></td>
<td>Big Five</td>
<td>Traditional Chinese</td>
<td>1-2</td>
<td>
<code class="literal">WIN950</code>, <code class="literal">Windows950</code>
</td>
</tr>
<tr>
<td><code class="literal">EUC_CN</code></td>
<td>Extended UNIX Code-CN</td>
<td>Simplified Chinese</td>
<td>1-3</td>
<td></td>
</tr>
<tr>
<td><code class="literal">EUC_JP</code></td>
<td>Extended UNIX Code-JP</td>
<td>Japanese</td>
<td>1-3</td>
<td></td>
</tr>
<tr>
<td><code class="literal">EUC_KR</code></td>
<td>Extended UNIX Code-KR</td>
<td>Korean</td>
<td>1-3</td>
<td></td>
</tr>
<tr>
<td><code class="literal">EUC_TW</code></td>
<td>Extended UNIX Code-TW</td>
<td>Traditional Chinese, Taiwanese</td>
<td>1-3</td>
<td></td>
</tr>
<tr>
<td><code class="literal">GB18030</code></td>
<td>National Standard</td>
<td>Chinese</td>
<td>1-2</td>
<td></td>
</tr>
<tr>
<td><code class="literal">GBK</code></td>
<td>Extended National Standard</td>
<td>Simplified Chinese</td>
<td>1-2</td>
<td>
<code class="literal">WIN936</code>, <code class="literal">Windows936</code>
</td>
</tr>
<tr>
<td><code class="literal">ISO_8859_5</code></td>
<td>ISO 8859-5, <acronym class="acronym">ECMA</acronym> 113</td>
<td>Latin/Cyrillic</td>
<td>1</td>
<td></td>
</tr>
<tr>
<td><code class="literal">ISO_8859_6</code></td>
<td>ISO 8859-6, <acronym class="acronym">ECMA</acronym> 114</td>
<td>Latin/Arabic</td>
<td>1</td>
<td></td>
</tr>
<tr>
<td><code class="literal">ISO_8859_7</code></td>
<td>ISO 8859-7, <acronym class="acronym">ECMA</acronym> 118</td>
<td>Latin/Greek</td>
<td>1</td>
<td></td>
</tr>
<tr>
<td><code class="literal">ISO_8859_8</code></td>
<td>ISO 8859-8, <acronym class="acronym">ECMA</acronym> 121</td>
<td>Latin/Hebrew</td>
<td>1</td>
<td></td>
</tr>
<tr>
<td><code class="literal">JOHAB</code></td>
<td><acronym class="acronym">JOHAB</acronym></td>
<td>Korean (Hangul)</td>
<td>1-3</td>
<td></td>
</tr>
<tr>
<td><code class="literal">KOI8</code></td>
<td>
<acronym class="acronym">KOI</acronym>8-R(U)</td>
<td>Cyrillic</td>
<td>1</td>
<td><code class="literal">KOI8R</code></td>
</tr>
<tr>
<td><code class="literal">LATIN1</code></td>
<td>ISO 8859-1, <acronym class="acronym">ECMA</acronym> 94</td>
<td>Western European</td>
<td>1</td>
<td><code class="literal">ISO88591</code></td>
</tr>
<tr>
<td><code class="literal">LATIN2</code></td>
<td>ISO 8859-2, <acronym class="acronym">ECMA</acronym> 94</td>
<td>Central European</td>
<td>1</td>
<td><code class="literal">ISO88592</code></td>
</tr>
<tr>
<td><code class="literal">LATIN3</code></td>
<td>ISO 8859-3, <acronym class="acronym">ECMA</acronym> 94</td>
<td>South European</td>
<td>1</td>
<td><code class="literal">ISO88593</code></td>
</tr>
<tr>
<td><code class="literal">LATIN4</code></td>
<td>ISO 8859-4, <acronym class="acronym">ECMA</acronym> 94</td>
<td>North European</td>
<td>1</td>
<td><code class="literal">ISO88594</code></td>
</tr>
<tr>
<td><code class="literal">LATIN5</code></td>
<td>ISO 8859-9, <acronym class="acronym">ECMA</acronym> 128</td>
<td>Turkish</td>
<td>1</td>
<td><code class="literal">ISO88599</code></td>
</tr>
<tr>
<td><code class="literal">LATIN6</code></td>
<td>ISO 8859-10, <acronym class="acronym">ECMA</acronym> 144</td>
<td>Nordic</td>
<td>1</td>
<td><code class="literal">ISO885910</code></td>
</tr>
<tr>
<td><code class="literal">LATIN7</code></td>
<td>ISO 8859-13</td>
<td>Baltic</td>
<td>1</td>
<td><code class="literal">ISO885913</code></td>
</tr>
<tr>
<td><code class="literal">LATIN8</code></td>
<td>ISO 8859-14</td>
<td>Celtic</td>
<td>1</td>
<td><code class="literal">ISO885914</code></td>
</tr>
<tr>
<td><code class="literal">LATIN9</code></td>
<td>ISO 8859-15</td>
<td>LATIN1 with Euro and accents</td>
<td>1</td>
<td>ISO885915</td>
</tr>
<tr>
<td><code class="literal">LATIN10</code></td>
<td>ISO 8859-16, <acronym class="acronym">ASRO</acronym> SR 14111</td>
<td>Romanian</td>
<td>1</td>
<td><code class="literal">ISO885916</code></td>
</tr>
<tr>
<td><code class="literal">MULE_INTERNAL</code></td>
<td>Mule internal code</td>
<td>Multilingual Emacs</td>
<td>1-4</td>
<td></td>
</tr>
<tr>
<td><code class="literal">SJIS</code></td>
<td>Shift JIS</td>
<td>Japanese</td>
<td>1-2</td>
<td>
<code class="literal">Mskanji</code>, <code class="literal">ShiftJIS</code>, <code class="literal">WIN932</code>, <code class="literal">Windows932</code>
</td>
</tr>
<tr>
<td><code class="literal">SQL_ASCII</code></td>
<td>unspecified (see text)</td>
<td><span class="emphasis"><em>any</em></span></td>
<td>1</td>
<td></td>
</tr>
<tr>
<td><code class="literal">UHC</code></td>
<td>Unified Hangul Code</td>
<td>Korean</td>
<td>1-2</td>
<td>
<code class="literal">WIN949</code>, <code class="literal">Windows949</code>
</td>
</tr>
<tr>
<td><code class="literal">UTF8</code></td>
<td>Unicode, 8-bit</td>
<td><span class="emphasis"><em>all</em></span></td>
<td>1-4</td>
<td><code class="literal">Unicode</code></td>
</tr>
<tr>
<td><code class="literal">WIN866</code></td>
<td>Windows CP866</td>
<td>Cyrillic</td>
<td>1</td>
<td><code class="literal">ALT</code></td>
</tr>
<tr>
<td><code class="literal">WIN874</code></td>
<td>Windows CP874</td>
<td>Thai</td>
<td>1</td>
<td></td>
</tr>
<tr>
<td><code class="literal">WIN1250</code></td>
<td>Windows CP1250</td>
<td>Central European</td>
<td>1</td>
<td></td>
</tr>
<tr>
<td><code class="literal">WIN1251</code></td>
<td>Windows CP1251</td>
<td>Cyrillic</td>
<td>1</td>
<td><code class="literal">WIN</code></td>
</tr>
<tr>
<td><code class="literal">WIN1252</code></td>
<td>Windows CP1252</td>
<td>Western European</td>
<td>1</td>
<td></td>
</tr>
<tr>
<td><code class="literal">WIN1256</code></td>
<td>Windows CP1256</td>
<td>Arabic</td>
<td>1</td>
<td></td>
</tr>
<tr>
<td><code class="literal">WIN1258</code></td>
<td>Windows CP1258</td>
<td>Vietnamese</td>
<td>1</td>
<td>
<code class="literal">ABC</code>, <code class="literal">TCVN</code>, <code class="literal">TCVN5712</code>, <code class="literal">VSCII</code>
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p> Not all <acronym class="acronym">API</acronym>s support all the listed character sets. For example, the
<span class="productname">PostgreSQL</span>
JDBC driver does not support <code class="literal">MULE_INTERNAL</code>, <code class="literal">LATIN6</code>,
<code class="literal">LATIN8</code>, and <code class="literal">LATIN10</code>.
</p>
<p> The <code class="literal">SQL_ASCII</code> setting behaves considerably differently
from the other settings. When the server character set is
<code class="literal">SQL_ASCII</code>, the server interprets byte values 0-127
according to the ASCII standard, while byte values 128-255 are taken
as uninterpreted characters. No encoding conversion will be done when
the setting is <code class="literal">SQL_ASCII</code>. Thus, this setting is not so
much a declaration that a specific encoding is in use, as a declaration
of ignorance about the encoding. In most cases, if you are
working with any non-ASCII data, it is unwise to use the
<code class="literal">SQL_ASCII</code> setting, because
<span class="productname">PostgreSQL</span> will be unable to help you by
converting or validating non-ASCII characters.
</p>
</div>
<div class="sect2" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="id664688"></a>21.2.2.Setting the Character Set</h3></div></div></div>
<p> <code class="command">initdb</code> defines the default character set
for a <span class="productname">PostgreSQL</span> cluster. For example,
</p>
<pre class="screen">initdb -E EUC_JP</pre>
<p>
sets the default character set (encoding) to
<code class="literal">EUC_JP</code> (Extended Unix Code for Japanese). You
can use <code class="option">--encoding</code> instead of
<code class="option">-E</code> if you prefer to type longer option strings.
If no <code class="option">-E</code> or <code class="option">--encoding</code> option is
given, <code class="command">initdb</code> attempts to determine the appropriate
encoding to use based on the specified or default locale.
</p>
<p> You can create a database with a different character set:
</p>
<pre class="screen">createdb -E EUC_KR korean</pre>
<p>
This will create a database named <code class="literal">korean</code> that
uses the character set <code class="literal">EUC_KR</code>. Another way to
accomplish this is to use this SQL command:
</p>
<pre class="programlisting">CREATE DATABASE korean WITH ENCODING 'EUC_KR';</pre>
<p>
The encoding for a database is stored in the system catalog
<code class="literal">pg_database</code>. You can see that by using the
<code class="option">-l</code> option or the <code class="command">\l</code> command
of <code class="command">psql</code>.
</p>
<pre class="screen">$ <strong class="userinput"><code>psql -l</code></strong>
List of databases
Database | Owner | Encoding
---------------+---------+---------------
euc_cn | t-ishii | EUC_CN
euc_jp | t-ishii | EUC_JP
euc_kr | t-ishii | EUC_KR
euc_tw | t-ishii | EUC_TW
mule_internal | t-ishii | MULE_INTERNAL
postgres | t-ishii | EUC_JP
regression | t-ishii | SQL_ASCII
template1 | t-ishii | EUC_JP
test | t-ishii | EUC_JP
utf8 | t-ishii | UTF8
(9 rows)</pre>
<p>
</p>
<div class="important" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Important</h3>
<p> Although you can specify any encoding you want for a database, it is
unwise to choose an encoding that is not what is expected by the locale
you have selected. The <code class="literal">LC_COLLATE</code> and
<code class="literal">LC_CTYPE</code> settings imply a particular encoding,
and locale-dependent operations (such as sorting) are likely to
misinterpret data that is in an incompatible encoding.
</p>
<p> Since these locale settings are frozen by <code class="command">initdb</code>, the
apparent flexibility to use different encodings in different databases
of a cluster is more theoretical than real. It is likely that these
mechanisms will be revisited in future versions of
<span class="productname">PostgreSQL</span>.
</p>
<p> One way to use multiple encodings safely is to set the locale to
<code class="literal">C</code> or <code class="literal">POSIX</code> during <code class="command">initdb</code>, thus
disabling any real locale awareness.
</p>
</div>
</div>
<div class="sect2" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="id664905"></a>21.2.3.Automatic Character Set Conversion Between Server and Client</h3></div></div></div>
<p> <span class="productname">PostgreSQL</span> supports automatic
character set conversion between server and client for certain
character sets. The conversion information is stored in the
<code class="literal">pg_conversion</code> system catalog. You can create a new
conversion by using the SQL command <code class="command">CREATE
CONVERSION</code>. <span class="productname">PostgreSQL</span> comes with some
predefined conversions. They are listed in <a href="multibyte.html#multibyte-translation-table" title="Table21.2.Client/Server Character Set Conversions">Table21.2, “Client/Server Character Set Conversions”</a>.
</p>
<div class="table">
<a name="multibyte-translation-table"></a><p class="title"><b>Table21.2.Client/Server Character Set Conversions</b></p>
<div class="table-contents"><table summary="Client/Server Character Set Conversions" border="1">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>Server Character Set</th>
<th>Available Client Character Sets</th>
</tr></thead>
<tbody>
<tr>
<td><code class="literal">BIG5</code></td>
<td>
<span class="emphasis"><em>not supported as a server encoding</em></span>
</td>
</tr>
<tr>
<td><code class="literal">EUC_CN</code></td>
<td>
<span class="emphasis"><em>EUC_CN</em></span>,
<code class="literal">MULE_INTERNAL</code>,
<code class="literal">UTF8</code>
</td>
</tr>
<tr>
<td><code class="literal">EUC_JP</code></td>
<td>
<span class="emphasis"><em>EUC_JP</em></span>,
<code class="literal">MULE_INTERNAL</code>,
<code class="literal">SJIS</code>,
<code class="literal">UTF8</code>
</td>
</tr>
<tr>
<td><code class="literal">EUC_KR</code></td>
<td>
<span class="emphasis"><em>EUC_KR</em></span>,
<code class="literal">MULE_INTERNAL</code>,
<code class="literal">UTF8</code>
</td>
</tr>
<tr>
<td><code class="literal">EUC_TW</code></td>
<td>
<span class="emphasis"><em>EUC_TW</em></span>,
<code class="literal">BIG5</code>,
<code class="literal">MULE_INTERNAL</code>,
<code class="literal">UTF8</code>
</td>
</tr>
<tr>
<td><code class="literal">GB18030</code></td>
<td>
<span class="emphasis"><em>not supported as a server encoding</em></span>
</td>
</tr>
<tr>
<td><code class="literal">GBK</code></td>
<td>
<span class="emphasis"><em>not supported as a server encoding</em></span>
</td>
</tr>
<tr>
<td><code class="literal">ISO_8859_5</code></td>
<td>
<span class="emphasis"><em>ISO_8859_5</em></span>,
<code class="literal">KOI8</code>,
<code class="literal">MULE_INTERNAL</code>,
<code class="literal">UTF8</code>,
<code class="literal">WIN866</code>,
<code class="literal">WIN1251</code>
</td>
</tr>
<tr>
<td><code class="literal">ISO_8859_6</code></td>
<td>
<span class="emphasis"><em>ISO_8859_6</em></span>,
<code class="literal">UTF8</code>
</td>
</tr>
<tr>
<td><code class="literal">ISO_8859_7</code></td>
<td>
<span class="emphasis"><em>ISO_8859_7</em></span>,
<code class="literal">UTF8</code>
</td>
</tr>
<tr>
<td><code class="literal">ISO_8859_8</code></td>
<td>
<span class="emphasis"><em>ISO_8859_8</em></span>,
<code class="literal">UTF8</code>
</td>
</tr>
<tr>
<td><code class="literal">JOHAB</code></td>
<td>
<span class="emphasis"><em>JOHAB</em></span>,
<code class="literal">UTF8</code>
</td>
</tr>
<tr>
<td><code class="literal">KOI8</code></td>
<td>
<span class="emphasis"><em>KOI8</em></span>,
<code class="literal">ISO_8859_5</code>,
<code class="literal">MULE_INTERNAL</code>,
<code class="literal">UTF8</code>,
<code class="literal">WIN866</code>,
<code class="literal">WIN1251</code>
</td>
</tr>
<tr>
<td><code class="literal">LATIN1</code></td>
<td>
<span class="emphasis"><em>LATIN1</em></span>,
<code class="literal">MULE_INTERNAL</code>,
<code class="literal">UTF8</code>
</td>
</tr>
<tr>
<td><code class="literal">LATIN2</code></td>
<td>
<span class="emphasis"><em>LATIN2</em></span>,
<code class="literal">MULE_INTERNAL</code>,
<code class="literal">UTF8</code>,
<code class="literal">WIN1250</code>
</td>
</tr>
<tr>
<td><code class="literal">LATIN3</code></td>
<td>
<span class="emphasis"><em>LATIN3</em></span>,
<code class="literal">MULE_INTERNAL</code>,
<code class="literal">UTF8</code>
</td>
</tr>
<tr>
<td><code class="literal">LATIN4</code></td>
<td>
<span class="emphasis"><em>LATIN4</em></span>,
<code class="literal">MULE_INTERNAL</code>,
<code class="literal">UTF8</code>
</td>
</tr>
<tr>
<td><code class="literal">LATIN5</code></td>
<td>
<span class="emphasis"><em>LATIN5</em></span>,
<code class="literal">UTF8</code>
</td>
</tr>
<tr>
<td><code class="literal">LATIN6</code></td>
<td>
<span class="emphasis"><em>LATIN6</em></span>,
<code class="literal">UTF8</code>
</td>
</tr>
<tr>
<td><code class="literal">LATIN7</code></td>
<td>
<span class="emphasis"><em>LATIN7</em></span>,
<code class="literal">UTF8</code>
</td>
</tr>
<tr>
<td><code class="literal">LATIN8</code></td>
<td>
<span class="emphasis"><em>LATIN8</em></span>,
<code class="literal">UTF8</code>
</td>
</tr>
<tr>
<td><code class="literal">LATIN9</code></td>
<td>
<span class="emphasis"><em>LATIN9</em></span>,
<code class="literal">UTF8</code>
</td>
</tr>
<tr>
<td><code class="literal">LATIN10</code></td>
<td>
<span class="emphasis"><em>LATIN10</em></span>,
<code class="literal">UTF8</code>
</td>
</tr>
<tr>
<td><code class="literal">MULE_INTERNAL</code></td>
<td>
<span class="emphasis"><em>MULE_INTERNAL</em></span>,
<code class="literal">BIG5</code>,
<code class="literal">EUC_CN</code>,
<code class="literal">EUC_JP</code>,
<code class="literal">EUC_KR</code>,
<code class="literal">EUC_TW</code>,
<code class="literal">ISO_8859_5</code>,
<code class="literal">KOI8</code>,
<code class="literal">LATIN1</code> to <code class="literal">LATIN4</code>,
<code class="literal">SJIS</code>,
<code class="literal">WIN866</code>,
<code class="literal">WIN1250</code>,
<code class="literal">WIN1251</code>
</td>
</tr>
<tr>
<td><code class="literal">SJIS</code></td>
<td>
<span class="emphasis"><em>not supported as a server encoding</em></span>
</td>
</tr>
<tr>
<td><code class="literal">SQL_ASCII</code></td>
<td>
<span class="emphasis"><em>any (no conversion will be performed)</em></span>
</td>
</tr>
<tr>
<td><code class="literal">UHC</code></td>
<td>
<span class="emphasis"><em>not supported as a server encoding</em></span>
</td>
</tr>
<tr>
<td><code class="literal">UTF8</code></td>
<td>
<span class="emphasis"><em>all supported encodings</em></span>
</td>
</tr>
<tr>
<td><code class="literal">WIN866</code></td>
<td>
<span class="emphasis"><em>WIN866</em></span>,
<code class="literal">ISO_8859_5</code>,
<code class="literal">KOI8</code>,
<code class="literal">MULE_INTERNAL</code>,
<code class="literal">UTF8</code>,
<code class="literal">WIN1251</code>
</td>
</tr>
<tr>
<td><code class="literal">WIN874</code></td>
<td>
<span class="emphasis"><em>WIN874</em></span>,
<code class="literal">UTF8</code>
</td>
</tr>
<tr>
<td><code class="literal">WIN1250</code></td>
<td>
<span class="emphasis"><em>WIN1250</em></span>,
<code class="literal">LATIN2</code>,
<code class="literal">MULE_INTERNAL</code>,
<code class="literal">UTF8</code>
</td>
</tr>
<tr>
<td><code class="literal">WIN1251</code></td>
<td>
<span class="emphasis"><em>WIN1251</em></span>,
<code class="literal">ISO_8859_5</code>,
<code class="literal">KOI8</code>,
<code class="literal">MULE_INTERNAL</code>,
<code class="literal">UTF8</code>,
<code class="literal">WIN866</code>
</td>
</tr>
<tr>
<td><code class="literal">WIN1252</code></td>
<td>
<span class="emphasis"><em>WIN1252</em></span>,
<code class="literal">UTF8</code>
</td>
</tr>
<tr>
<td><code class="literal">WIN1256</code></td>
<td>
<span class="emphasis"><em>WIN1256</em></span>,
<code class="literal">UTF8</code>
</td>
</tr>
<tr>
<td><code class="literal">WIN1258</code></td>
<td>
<span class="emphasis"><em>WIN1258</em></span>,
<code class="literal">UTF8</code>
</td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p> To enable automatic character set conversion, you have to
tell <span class="productname">PostgreSQL</span> the character set
(encoding) you would like to use in the client. There are several
ways to accomplish this:
</p>
<div class="itemizedlist"><ul type="disc">
<li>
<p> Using the <code class="command">\encoding</code> command in
<span class="application">psql</span>.
<code class="command">\encoding</code> allows you to change client
encoding on the fly. For
example, to change the encoding to <code class="literal">SJIS</code>, type:
</p>
<pre class="programlisting">\encoding SJIS</pre>
<p>
</p>
</li>
<li>
<p> Using <span class="application">libpq</span> functions.
<code class="command">\encoding</code> actually calls
<code class="function">PQsetClientEncoding()</code> for its purpose.
</p>
<pre class="synopsis">int PQsetClientEncoding(PGconn *<em class="replaceable"><code>conn</code></em>, const char *<em class="replaceable"><code>encoding</code></em>);</pre>
<p>
where <em class="replaceable"><code>conn</code></em> is a connection to the server,
and <em class="replaceable"><code>encoding</code></em> is the encoding you
want to use. If the function successfully sets the encoding, it returns 0,
otherwise -1. The current encoding for this connection can be determined by
using:
</p>
<pre class="synopsis">int PQclientEncoding(const PGconn *<em class="replaceable"><code>conn</code></em>);</pre>
<p>
Note that it returns the encoding ID, not a symbolic string
such as <code class="literal">EUC_JP</code>. To convert an encoding ID to an encoding name, you
can use:
</p>
<pre class="synopsis">char *pg_encoding_to_char(int <em class="replaceable"><code>encoding_id</code></em>);</pre>
<p>
</p>
</li>
<li>
<p> Using <code class="command">SET client_encoding TO</code>.
Setting the client encoding can be done with this SQL command:
</p>
<pre class="programlisting">SET CLIENT_ENCODING TO '<em class="replaceable"><code>value</code></em>';</pre>
<p>
Also you can use the more standard SQL syntax <code class="literal">SET NAMES</code> for this purpose:
</p>
<pre class="programlisting">SET NAMES '<em class="replaceable"><code>value</code></em>';</pre>
<p>
To query the current client encoding:
</p>
<pre class="programlisting">SHOW client_encoding;</pre>
<p>
To return to the default encoding:
</p>
<pre class="programlisting">RESET client_encoding;</pre>
<p>
</p>
</li>
<li><p> Using <code class="envar">PGCLIENTENCODING</code>. If the environment variable
<code class="envar">PGCLIENTENCODING</code> is defined in the client's
environment, that client encoding is automatically selected
when a connection to the server is made. (This can
subsequently be overridden using any of the other methods
mentioned above.)
</p></li>
<li><p> Using the configuration variable <a href="runtime-config-client.html#guc-client-encoding">client_encoding</a>. If the
<code class="varname">client_encoding</code> variable is set, that client
encoding is automatically selected when a connection to the
server is made. (This can subsequently be overridden using any
of the other methods mentioned above.)
</p></li>
</ul></div>
<p>
</p>
<p> If the conversion of a particular character is not possible
[mdash ] suppose you chose <code class="literal">EUC_JP</code> for the
server and <code class="literal">LATIN1</code> for the client, then some
Japanese characters cannot be converted to
<code class="literal">LATIN1</code> [mdash ] it is transformed to its
hexadecimal byte values in parentheses, e.g.,
<code class="literal">(826C)</code>.
</p>
<p> If the client character set is defined as <code class="literal">SQL_ASCII</code>,
encoding conversion is disabled, regardless of the server's character
set. Just as for the server, use of <code class="literal">SQL_ASCII</code> is unwise
unless you are working with all-ASCII data.
</p>
</div>
<div class="sect2" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="id666163"></a>21.2.4.Further Reading</h3></div></div></div>
<p> These are good sources to start learning about various kinds of encoding
systems.
</p>
<div class="variablelist"><dl>
<dt><span class="term"><a href="http://www.i18ngurus.com/docs/984813247.html" target="_top">http://www.i18ngurus.com/docs/984813247.html</a></span></dt>
<dd><p> An extensive collection of documents about character sets, encodings,
and code pages.
</p></dd>
<dt><span class="term"><a href="ftp://ftp.ora.com/pub/examples/nutshell/ujip/doc/cjk.inf" target="_top">ftp://ftp.ora.com/pub/examples/nutshell/ujip/doc/cjk.inf</a></span></dt>
<dd><p> Detailed explanations of <code class="literal">EUC_JP</code>,
<code class="literal">EUC_CN</code>, <code class="literal">EUC_KR</code>,
<code class="literal">EUC_TW</code> appear in section 3.2.
</p></dd>
<dt><span class="term"><a href="http://www.unicode.org/" target="_top">http://www.unicode.org/</a></span></dt>
<dd><p> The web site of the Unicode Consortium
</p></dd>
<dt><span class="term">RFC 2044</span></dt>
<dd><p> <acronym class="acronym">UTF</acronym>-8 is defined here.
</p></dd>
</dl></div>
<p>
</p>
</div>
</div></body>
</html>
|