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_HEX function

Focus mode
TO_HEX function - Amazon Redshift

TO_HEX converts a number or binary value to a hexadecimal representation.

Syntax

TO_HEX(value)

Arguments

value

Either a number or binary value (VARBYTE) to be converted.

Return type

VARCHAR

Examples

To convert a number to its hexadecimal representation, use the following example.

SELECT TO_HEX(2147676847); +----------+ | to_hex | +----------+ | 8002f2af | +----------+

To convert the VARBYTE representation of 'abc' to a hexadecimal number, use the followign example.

SELECT TO_HEX('abc'::VARBYTE); +--------+ | to_hex | +--------+ | 616263 | +--------+

To create a table, insert the VARBYTE representation of 'abc' to a hexadecimal number, and select the column with the value, use the following example.

CREATE TABLE t (vc VARCHAR); INSERT INTO t SELECT TO_HEX('abc'::VARBYTE); SELECT vc FROM t; +--------+ | vc | +--------+ | 616263 | +--------+

To show that when casting a VARBYTE value to VARCHAR the format is UTF-8, use the following example.

CREATE TABLE t (vc VARCHAR); INSERT INTO t SELECT 'abc'::VARBYTE::VARCHAR; SELECT vc FROM t; +-----+ | vc | +-----+ | abc | +-----+

On this page

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.