to_hex()

A function for converting an integer into hexadecimal

to_hex() is a system function  for converting an integer into its hexadecimal string replacement.

to_hex() was added in PostgreSQL 7.3.

Usage

to_hex ( integer ) → text
to_hex ( bigint ) → text

Change history

Examples

Basic usage example for to_hex():

postgres=# SELECT to_hex(255);
 to_hex 
--------
 ff
(1 row)

Converting a bigint to hexadecimal:

postgres=# SELECT to_hex(-2401053088876216593);
      to_hex      
------------------
 deadbeefdeadbeef
(1 row)

Categories

String manipulation, System function

See also

encode()