convert_from()

A function for converting a bytea string to the database encoding

convert_from() is a system function for converting a bytea string containing text from the specified encoding to the database's encoding.

convert_from() was added in PostgreSQL 8.3.

Usage

convert_from ( bytes bytea, src_encoding name ) → text

An ERROR is raised if the source encoding is not compatible with the database encoding, or the provided string contains an invalid byte sequence for the source encoding.

convert_to() provides the equivalent functionality for converting a string from the database encoding to a specified encoding. convert provides functionality to convert between user-specified encodings.

Change history

Examples

Basic usage example for convert_from():

postgres=# SELECT convert_from('\xe4', 'LATIN1');
 convert_from 
--------------
 ä
(1 row)

Attempting to perform a conversion where the provided string contains an invalid byte sequence for the specified source encoding:

postgres=# SELECT convert_from('\xe4', 'SJIS');
ERROR:  invalid byte sequence for encoding "SJIS": 0xe4

Categories

Locale and character set handling, String manipulation, System function

See also

convert_to(), convert(), server_encoding