to_hex

Formats a BLOB-backed EVM byte value as uppercase hexadecimal text without a 0x prefix. hex and to_hex are compatibility aliases with identical behavior.

Example

Local

1
-- to_hex is the compatibility alias of hex
2
SELECT to_hex('0xa9059cbb'::BYTES4) AS selector_hex;
3
-- => [{"selector_hex":"A9059CBB"}]
Notebook ready in readonly mode.

API reference

Exact signatures with descriptions, requirements, inputs, returns, and examples.

to_hex(ADDRESS) #

Returns uppercase hexadecimal for the stored bytes of ADDRESS, BYTES4, BYTES32, or BYTES256.

Inputs

Name Type Use
value ADDRESS

ADDRESS, BYTES4, BYTES32, or BYTES256 value encoded exactly as stored.

required positional

Returns

Name Type
hex VARCHAR

Uppercase hexadecimal text. Returns two uppercase hex characters per stored byte, without a 0x prefix. NULL returns NULL.

3 additional overloads
to_hex(BYTES4) #

Returns uppercase hexadecimal for the stored bytes of ADDRESS, BYTES4, BYTES32, or BYTES256.

Inputs

Name Type Use
value BYTES4

ADDRESS, BYTES4, BYTES32, or BYTES256 value encoded exactly as stored.

required positional

Returns

Name Type
hex VARCHAR

Uppercase hexadecimal text. Returns two uppercase hex characters per stored byte, without a 0x prefix. NULL returns NULL.

to_hex(BYTES32) #

Returns uppercase hexadecimal for the stored bytes of ADDRESS, BYTES4, BYTES32, or BYTES256.

Inputs

Name Type Use
value BYTES32

ADDRESS, BYTES4, BYTES32, or BYTES256 value encoded exactly as stored.

required positional

Returns

Name Type
hex VARCHAR

Uppercase hexadecimal text. Returns two uppercase hex characters per stored byte, without a 0x prefix. NULL returns NULL.

to_hex(BYTES256) #

Returns uppercase hexadecimal for the stored bytes of ADDRESS, BYTES4, BYTES32, or BYTES256.

Inputs

Name Type Use
value BYTES256

ADDRESS, BYTES4, BYTES32, or BYTES256 value encoded exactly as stored.

required positional

Returns

Name Type
hex VARCHAR

Uppercase hexadecimal text. Returns two uppercase hex characters per stored byte, without a 0x prefix. NULL returns NULL.

Category and tags

Category
EVM utilities
Tag
Bytes
Tag
Hex
Tag
EVM
Tag
Types