convert_to()

A function for converting text into a bytea string with a specified encoding

convert_to() is a system function|] ]for converting a text string in the database's encoding to a bytea string in the specified encoding.

convert_to() was added in PostgreSQL 8.3.

Usage

convert_to ( string text, dest_encoding name ) → bytea

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

Change history

Examples

Basic usage example for convert_to():

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

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

postgres=# SELECT convert_to('ä', 'SJIS');
ERROR:  character with byte sequence 0xc3 0xa4 in encoding "UTF8" has no equivalent in encoding "SJIS"

Categories

Locale and character set handling, String manipulation, System function

See also

convert_from(), convert(), server_encoding