【鼠】庚子年癸未月乙卯日 / 五月廿二日
Saturday July 11, 2020

PostgreSQL

Since PostgreSQL 7.3 multibyte support is enabled by default and the --enable-multibyte option was removed. Also from 7.3 onwards support for GB18030 was added.

Multibyte (MB) support allows PostgreSQL to handle multiple-byte character sets such as EUC (Extended Unix Code), Unicode, and Mule internal code. It allows you to use multibyte character sets in regular expressions (regexp), LIKE, and some other functions. The default encoding system is selected while initializing your PostgreSQL installation using initdb. Note that this can be overridden when you create a database using createdb or by using the SQL command CREATE DATABASE. So you can have multiple databases each with a different encoding system. When no option is used the default encoding (SQL_ASCII) is used.

set default encoding : initdb -E encoding
using createdb : createdb -E encoding
using CREATE DATABASE : CREATE DATABASE name WITH ENCODING=encoding
Where encoding for Chinese can be EUC_CN, EUC_TW or UNICODE.

The encoding for a database is represented as an encoding column in the pg_database system catalog. You can see that by using the -l option or the \l command of psql.

PostgreSQL supports an automatic encoding conversion between server and client for some encodings. The conversion info is stored in pg_conversion system catalog. You can create a new conversion by using CREATE CONVERSION. PostgreSQL comes with some predefined conversions.
For the server-encoding EUC_CN the following client encodings are available : EUC_CN, UNICODE, MULE_INTERNAL.
For the server-encoding EUC_TW the following client encodings are available : EUC_TW, BIG5, UNICODE, MULE_INTERNAL
For the server-encoding UNICODE the following client encodings are available : EUC_JP, SJIS, EUC_KR, UHC, JOHAB, EUC_CN, GBK, EUC_TW, BIG5, LATIN1 to LATIN10, ISO_8859_5, ISO_8859_6, ISO_8859_7, ISO_8859_8, WIN, ALT, KOI8, WIN1256, TCVN, WIN874, GB18030, WIN1250
To enable the automatic encoding translation, you have to tell PostgreSQL the encoding you would like to use in the client. There are several ways to accomplish this (see PostgreSQL-website for more information).

Link: PostgreSQL

[ < back ] - [ home ]