Returns the hexadecimal representation of numeric, string, or binary data.


Beginning with version 8.5, the way HEX() calculates the values of real and decimal numbers is changed to be more in line with how MySQL HEX() works. Existing implementations of HEX() will return updated values.


HEX (expression)


  • expression: any valid expression. This can be a column name, literal, or the return value of another function.

Return Type

Upper-case hexadecimal string.


| HEX(1234) |
| 4D2       |
SELECT HEX('1234');
| HEX('1234') |
| 31323334    |
SELECT HEX('ohai');
| HEX('ohai') |
| 6F686169    |


This function operates on the binary representation of the given argument. That is why the result of hex(1234) and hex('1234') yield different values. This also means that the output of hex( number ) cannot be fed directly into UNHEX to get back the literal number 1234.


Deprecation Notice

String functions, such as CONCAT, LENGTH, SUBSTR, and HEX, previously operated on the JSON representation of a vector, interpreted as a string. This behavior is deprecated. In the 8.7 release, string functions operate on the binary representation of a vector.

If you truly intend to use a string function on the JSON string representation of a vector, you can write code in the following way so that it will run the same way before and after this behavior change.

Suppose that vec is a vector-type value and stringfunc is any string function and you have expression:


you can change it to:

stringfunc(vec :> json)

Last modified: June 6, 2024

Was this article helpful?