RefLib

Reference library for AI

Back

postgresql_16:4.9.3.3 Automatic Character Set Conversion Between Server and Client

PostgreSQL 16 > Server Administration > Localization > Character Set Support > Automatic Character Set Conversion Between Server and Client

PostgreSQL supports automatic character set conversion between server and client for many combinations of character sets ((see postgresql_16:4.9.3.4) shows which ones).

To enable automatic character set conversion, you have to tell PostgreSQL the character set (encoding) you would like to use in the client. There are several ways to accomplish this: Using the \encoding command in psql. \encoding allows you to change client encoding on the fly. For example, to change the encoding to SJIS, type: \encoding SJIS libpq ((see postgresql_16:5.1.11)) has functions to control the client encoding. Using SET client_encoding TO. Setting the client encoding can be done with this SQL command: SET CLIENT_ENCODING TO '*value*'; Also you can use the standard SQL syntax SET NAMES for this purpose: SET NAMES '*value*'; To query the current client encoding: SHOW client_encoding; To return to the default encoding: RESET client_encoding; Using PGCLIENTENCODING. If the environment variable PGCLIENTENCODING 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.) Using the configuration variable (see guc-client-encoding). If the client_encoding 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.)

If the conversion of a particular character is not possible — suppose you chose EUC_JP for the server and LATIN1 for the client, and some Japanese characters are returned that do not have a representation in LATIN1 — an error is reported.

If the client character set is defined as SQL_ASCII, encoding conversion is disabled, regardless of the server's character set. (However, if the server's character set is not SQL_ASCII, the server will still check that incoming data is valid for that encoding; so the net effect is as though the client character set were the same as the server's.) Just as for the server, use of SQL_ASCII is unwise unless you are working with all-ASCII data.

Back