PostgreSQL to_hex() Function

The PostgreSQL to_hex() function converts the specified number to a hexadecimal representation and returns the result.

to_hex() Syntax

This is the syntax of the PostgreSQL to_hex() function:

to_hex(number)

Parameters

number

Required. An integer to convert.

Return value

The PostgreSQL to_hex() function returns a string that is the hexadecimal representation of the specified number.

to_hex() Examples

This example shows how to use to_hex() to convert a number to hexadecimal representation:

SELECT
    to_hex(9) AS "to_hex(9)",
    to_hex(10) AS "to_hex(10)",
    to_hex(11) AS "to_hex(11)",
    to_hex(12) AS "to_hex(12)",
    to_hex(13) AS "to_hex(13)",
    to_hex(14) AS "to_hex(14)",
    to_hex(15) AS "to_hex(15)",
    to_hex(16) AS "to_hex(16)",
    to_hex(17) AS "to_hex(17)",
    to_hex(123456789) AS "to_hex(123456789)";
-[ RECORD 1 ]-----+--------
to_hex(9)         | 9
to_hex(10)        | a
to_hex(11)        | b
to_hex(12)        | c
to_hex(13)        | d
to_hex(14)        | e
to_hex(15)        | f
to_hex(16)        | 10
to_hex(17)        | 11
to_hex(123456789) | 75bcd15