Contents
pg_encoding_to_char()
pg_encoding_to_char()
is a system function for converting an encoding's internal identifier to a human-readble name.
pg_encoding_to_char()
was added in PostgreSQL 7.0.
Usage
pg_encoding_to_char (integer
) →name
In system catalog relations, references to individual encodings are stored as integers, as defined in the C enum pg_enc
in src/include/mb/pg_wchar.h (note there is no guarantee these values will remain stable across PostgreSQL releases). pg_encoding_to_char()
can be used to convert these integer values to a human-readable format.
The following system catalog tables contain encoding references as integers:
pg_collation
(columncollencoding
)pg_conversion
(columnsconforencoding
andcontoencoding
)pg_database
(columnencoding
)
Prior to PostgreSQL 15, this function was not referenced in the PostgreSQL documentation.
Change history
- PostgreSQL 15
- documentation added (commit f6b5d05b)
- PostgreSQL 7.0
- added (commit 5eb1d0de)
Examples
Basic usage example for pg_encoding_to_char()
:
postgres=# SELECT pg_encoding_to_char(1); pg_encoding_to_char --------------------- EUC_JP (1 row)
A more practical example converting the encoding
column in pg_database
to a human-readable value:
postgres=# SELECT datname, pg_encoding_to_char(encoding) AS encoding FROM pg_database ORDER BY 1; datname | encoding -----------+---------- foo | EUC_JP postgres | UTF8 template0 | UTF8 template1 | UTF8 (4 rows)
An empty string is returned if an invalid encoding number is provided:
postgres=# SELECT pg_encoding_to_char(-1), pg_encoding_to_char(-1) IS NULL; pg_encoding_to_char | ?column? ---------------------+---------- | f (1 row)