Convert between different character encodings.
number_1
, number_2
, …, number_n
(numeric): Numerical arguments interpreted as integers. Types: Int
, Float
.String
.UInt8
data type, it is converted to UInt8
with possible rounding and overflow.0x
) or suffixes (like h
).
For integer arguments, it prints hex digits from the most significant to least significant (big-endian or “human-readable” order). It starts with the most significant non-zero byte (leading zero bytes are omitted) but always prints both digits of every byte even if the leading digit is zero.
Alias:
arg
(String
, UInt
, Float
, Decimal
, Date
, DateTime
, or UUID
): A value to convert to hexadecimal.String
.Float
and Decimal
types, the values are encoded as their representation in memory. As ClickHouse supports little-endian architecture, they are encoded in little-endian. Zero leading/trailing bytes are not omitted.Date
and DateTime
types, the values are formatted as corresponding integers (the number of days since Epoch for Date
and the value of Unix Timestamp for DateTime
).String
and FixedString
types, all bytes are encoded as two hexadecimal numbers. Zero bytes are not omitted.UUID
type, the values are encoded in big-endian order.hex
. It interprets each pair of hexadecimal digits in the argument as a number and converts it to the byte represented by that number. The return value is a binary string (BLOB).
If you want to convert the result to a number, you can use the reverse
and reinterpretAs<Type>
functions.
Syntax:
arg
(String
, FixedString
): A string containing any number of hexadecimal digits.String
)unhex
to convert the hexadecimal string ‘FFF’ to its binary representation, reverse the bytes (since ClickHouse uses little-endian), and then reinterpret the result as a UInt64.
unhex()
does not perform the inverse of hex(N)
.Date
and DateTime
, it formats as corresponding integers (the number of days since Epoch for Date and the value of Unix Timestamp for DateTime).String
and FixedString
, all bytes are encoded as eight binary numbers. Zero bytes are not omitted.Float
and Decimal
types, they are encoded as their representation in memory (little-endian). Zero leading/trailing bytes are not omitted.UUID
type, it is encoded as a big-endian order string.arg
(String
, FixedString
, UInt
, Float
, Decimal
, Date
, or DateTime
): A value to convert to binary.String
.bin
function converts the integer 14 to its binary representation, resulting in the string ‘00001110’.
bin
function converts a UUID to its binary representation. The UUID ‘61f0c404-5cb3-11e7-907b-a6006ad3dba0’ is represented as a 128-bit number, and the bin
function outputs its binary form as a string of 128 binary digits. This can be useful for visualizing the binary structure of UUIDs, which are often used as unique identifiers in databases and distributed systems.
bin
. It interprets each pair of binary digits in the argument as a number and converts it to the byte represented by that number.
Syntax:
arg
(String
): A string containing any number of binary digits.String
)unbin()
does not return the inverse of bin()
.unbin
is invoked from within the clickhouse-client, binary strings are displayed using UTF-8.reverse
and reinterpretAs<Type>
functions:
num
(Int/UInt
): An integer value representing the bitmask.String
)num
(Int/UInt
): An integer value representing the bitmask.UInt64
numbers containing the list of powers of two that sum up to the source number. The numbers in the array are in ascending order. (Array(UInt64)
)arg
(Int/UInt
): Integer value.Array(UInt64)
.arg1
, arg2
, …, argN
(UInt8
, UInt16
, UInt32
, UInt64
): Up to 8 unsigned integers or columns of unsigned integer types.UInt64
code.
Example:
range_mask
(Tuple
): A tuple specifying the amount of range expansion for each argument (1-8x).arg1
, arg2
, …, argN
(UInt8
, UInt16
, UInt32
, UInt64
): Up to 8 unsigned integers or columns of unsigned integer types.UInt64
code.
Example:
tuple_size
(Integer
): Integer value no more than 8.code
(UInt64
): UInt64 code.UInt64
values.
Example:
range_mask
(Tuple
): A tuple specifying bit shifts for each dimension.code
(UInt64
): UInt64 code.UInt64
values.
Example:
arg1
, arg2
(UInt
): Up to 2 unsigned integers or columns of unsigned integer type.UInt64
code representing the Hilbert curve index.
Example:
range_mask
(Tuple
): A tuple specifying bit shifts for each dimension.arg1
, arg2
(UInt
): Up to 2 unsigned integers or columns of unsigned integer type.UInt64
code representing the Hilbert curve index.
Example:
tuple_size
(Integer
): Integer value no more than 2.code
(UInt64
): UInt64 code.UInt64
values.
Example:
range_mask
(Tuple
): A tuple specifying bit shifts for each dimension.code
(UInt64
): UInt64 code.UInt64
values.
Example: