Cloud

decode

The decode() function decodes text data into binary (bytea) data using a specified format. It is the inverse of encode().

Syntax

The syntax of the decode() function is:

DECODE(string, format)

The decode() function requires two arguments:

  • string: The text value to decode.

  • format: The format that string is encoded in. Supported values are hex, base64, and escape.

Examples

Decode a hex string

This example decodes a hexadecimal string back into binary data:

SELECT DECODE('deadbeef', 'hex');
+--------------+
| decode       |
+--------------+
| \xdeadbeef   |
+--------------+

Decode a base64 string

This example decodes a base64 string back into binary data:

SELECT DECODE('SGVsbG8=', 'base64');
+---------------+
| decode        |
+---------------+
| \x48656c6c6f  |
+---------------+