pg_char_to_encoding()

A function for converting an encoding name to its internal identifier

pg_char_to_encoding() is a system function for converting an encoding name to the internal integer identifier used in system catalog relations.

pg_char_to_encoding() was added in PostgreSQL 7.0.

Usage

pg_char_to_encoding ( name ) → integer

The returned value is that of the identifier 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.

-1 is returned if the provided encoding name does not match a known encoding.

As of PostgreSQL 14, this function is not referenced in the PostgreSQL documentation.

Change history

Examples

Basic usage example for pg_char_to_encoding():

postgres=# SELECT pg_char_to_encoding('UTF8');
 pg_char_to_encoding 
---------------------
                   6
(1 row)

Using an unknown encoding name:

postgres=# SELECT pg_char_to_encoding('foo');
 pg_char_to_encoding 
---------------------
                  -1
(1 row)

Categories

Locale and character set handling, System function

See also

pg_encoding_to_char()