Cloud

encode

The encode() function encodes binary (bytea) data into a text representation using a specified format. See also decode() to reverse this operation.

Syntax

The syntax of the encode() function is:

ENCODE(data, format)

The encode() function requires two arguments:

  • data: The bytea value to encode.

  • format: The encoding format to use. Supported values are hex, base64, and escape.

Examples

Encode binary data as hex

This example encodes a bytea value as a hexadecimal string:

SELECT ENCODE('\xdeadbeef'::bytea, 'hex');
+------------+
| encode     |
+------------+
| deadbeef   |
+------------+

Encode binary data as base64

This example encodes a bytea value as a base64 string:

SELECT ENCODE('\x48656c6c6f'::bytea, 'base64');
+------------+
| encode     |
+------------+
| SGVsbG8=   |
+------------+