CONVERT_TO

This is a function for converting a text string in the database's encoding to a bytea string in the specified encoding.

Syntax

convert_to ( string text, dest_encoding name ) → bytea

Remarks

  • 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.

  • CONVERT_FROM provides the equivalent functionality for converting a bytea string containing text from the specified encoding to the database's encoding.

Example

SELECT convert_to('sample_text', 'UTF8') 

Returns the binary value 73616d706c655f74657874.