Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

TO_VARBYTE function - Amazon Redshift

TO_VARBYTE function

TO_VARBYTE converts a string in a specified format to a binary value.

Syntax

TO_VARBYTE(string, format)

Arguments

string

A CHAR or VARCHAR string.

format

The format of the input string. Case insensitive valid values are hex, binary, utf8 (also utf-8 and utf_8), and base64.

Return type

VARBYTE

Examples

To convert the hex 6162 to a binary value, use the following example. The result is automatically shown as the hexadecimal representation of the binary value.

SELECT TO_VARBYTE('6162', 'hex'); +------------+ | to_varbyte | +------------+ | 6162 | +------------+

To return the binary representation of 4d, use the following example. The binary representation of '4d' is 01001101.

SELECT TO_VARBYTE('01001101', 'binary'); +------------+ | to_varbyte | +------------+ | 4d | +------------+

To convert the string 'a' in UTF-8 to a binary value, use the following example. The result is automatically shown as the hexadecimal representation of the binary value.

SELECT TO_VARBYTE('a', 'utf8'); +------------+ | to_varbyte | +------------+ | 61 | +------------+

To convert the string '4' in hexadecimal to a binary value, use the following example. If the hexadecimal string length is an odd number, then a 0 is prepended to form a valid hexadecimal number.

SELECT TO_VARBYTE('4', 'hex'); +------------+ | to_varbyte | +------------+ | 04 | +------------+
PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.