Documentation Index
Fetch the complete documentation index at: https://private-7c7dfe99-page-updates.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
bech32Decode
Introduced in: v25.6.0 Decodes a Bech32 address string generated by either the bech32 or bech32m algorithms.Unlike the encode function,
bech32Decode will automatically handle padded FixedStrings.address— A Bech32 string to decode.StringorFixedStringmode— Optional. Pass'raw'to decode without stripping the first byte as a witness version. Use this for non-SegWit addresses (e.g. Cosmos SDK).String
(hrp, data) that was used to encode the string. The data is in binary format. Tuple(String, String)
Examples
Decode address
Query
Response
Query
Response
bech32Encode
Introduced in: v25.6.0 Encodes a binary data string, along with a human-readable part (HRP), using the Bech32 or Bech32m algorithms.When using the
FixedString data type, if a value does not fully fill the row it is padded with null characters.
While the bech32Encode function will handle this automatically for the hrp argument, for the data argument the values must not be padded.
For this reason it is not recommended to use the FixedString data type for your data values unless you are
certain that they are all the same length and ensure that your FixedString column is set to that length as well.hrp— A String of1 - 83lowercase characters specifying the “human-readable part” of the code. Usually ‘bc’ or ‘tb’.StringorFixedStringdata— A String of binary data to encode.StringorFixedStringwitver_or_variant— Optional. Either a UInt* witness version (default = 1,0for Bech32,1+ for Bech32m) or a String encoding variant:'bech32'(BIP173) or'bech32m'(BIP350). When a string variant is used, no witness version byte is prepended — this is needed for non-SegWit addresses such as Cosmos SDK.UInt*orString
String
Examples
Default Bech32m
Query
Response
Query
Response
Query
Response
Query
Response
bin
Introduced in: v21.8.0 Returns a string containing the argument’s binary representation according to the following logic for different types:| Type | Description |
|---|---|
(U)Int* | Prints bin 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 eight digits of every byte if the leading digit is zero. |
Date and DateTime | Formatted 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 simply encoded as eight binary numbers. Zero bytes are not omitted. |
Float* and Decimal | Encoded as their representation in memory. As we support little-endian architecture, they are encoded in little-endian. Zero leading/trailing bytes are not omitted. |
UUID | Encoded as big-endian order string. |
arg— A value to convert to binary.StringorFixedStringor(U)Int*orFloat*orDecimalorDateorDateTime
String
Examples
Simple integer
Query
Response
Query
Response
Query
Response
Query
Response
bitPositionsToArray
Introduced in: v21.7.0 This function returns the positions (in ascending order) of the 1 bits in the binary representation of an unsigned integer. Signed input integers are first casted to an unsigned integer. Syntaxarg— An integer value.(U)Int*
Array(UInt64)
Examples
Single bit set
Query
Response
Query
Response
bitmaskToArray
Introduced in: v1.1.0 This function decomposes an integer into a sum of powers of two. The powers of two are returned as an ascendingly ordered array. Syntaxnum— An integer value.(U)Int*
Array(UInt64)
Examples
Basic example
Query
Response
Query
Response
bitmaskToList
Introduced in: v1.1.0 Like bitmaskToArray but returns the powers of two as a comma-separated string. Syntaxnum— An integer value.(U)Int*
String
Examples
Basic example
Query
Response
char
Introduced in: v20.1.0 Returns a string with length equal to the number of arguments passed where each byte has the value of the corresponding argument. Accepts multiple arguments of numeric types. If the value of the argument is out of range of theUInt8 data type, then it is converted
to UInt8 with potential rounding and overflow.
Syntax
num1[, num2[, num3 ...]]— Numerical arguments interpreted as integers.(U)Int8/16/32/64orFloat*
String
Examples
Basic example
Query
Response
Query
Response
hex
Introduced in: v1.1.0 Returns a string containing the argument’s hexadecimal representation according to the following logic for different types:| Type | Description |
|---|---|
(U)Int* | Prints hex digits (“nibbles”) 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. |
Date and DateTime | Formatted 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 simply encoded as two hexadecimal numbers. Zero bytes are not omitted. |
Float* and Decimal | Encoded as their representation in memory. ClickHouse represents the values internally always as little endian, therefore they are encoded as such. Zero leading/trailing bytes are not omitted. |
UUID | Encoded as big-endian order string. |
A-F and not using any prefixes (like 0x) or suffixes (like h).
Syntax
String
Examples
Simple integer
Query
Response
Query
Response
Query
Response
Query
Response
hilbertDecode
Introduced in: v24.6.0 Decodes a Hilbert curve index back into a tuple of unsigned integers, representing coordinates in multi-dimensional space. As with thehilbertEncode function, this function has two modes of operation:
- Simple
- Expanded
UInt64 code.
Expanded mode
Accepts a range mask (tuple) as a first argument and up to 2 unsigned integers as
other arguments. Each number in the mask configures the number of bits by which
the corresponding argument will be shifted left, effectively scaling the argument
within its range.
Range expansion can be beneficial when you need a similar distribution for
arguments with wildly different ranges (or cardinality) For example: ‘IP Address’ (0...FFFFFFFF)
and ‘Country code’ (0...FF). As with the encode function, this is limited to 8
numbers at most.
Syntax
tuple_size— Integer value of no more than2.UInt8/16/32/64orTuple(UInt8/16/32/64)code—UInt64code.UInt64
Tuple(UInt64)
Examples
Simple mode
Query
Response
Query
Response
Query
Response
Query
Response
hilbertEncode
Introduced in: v24.6.0 Calculates code for Hilbert Curve for a list of unsigned integers. The function has two modes of operation:- Simple
- Expanded
args— Up to twoUIntvalues or columns of typeUInt.UInt8/16/32/64range_mask— For the expanded mode, up to twoUIntvalues or columns of typeUInt.UInt8/16/32/64
UInt64 code. UInt64
Examples
Simple mode
Query
Response
Query
Response
Query
Response
Query
Response
Query
Response
mortonDecode
Introduced in: v24.6.0 Decodes a Morton encoding (ZCurve) into the corresponding unsigned integer tuple. As with themortonEncode function, this function has two modes of operation:
- Simple
- Expanded
1- no shrink2- 2x shrink3- 3x shrink ⋮- Up to 8x shrink.
(0...FFFFFFFF)
and ‘Country code’ (0...FF). As with the encode function, this is limited to
8 numbers at most.
Syntax
tuple_size— Integer value no more than 8.UInt8/16/32/64range_mask— For the expanded mode, the mask for each argument. The mask is a tuple of unsigned integers. Each number in the mask configures the amount of range shrink.Tuple(UInt8/16/32/64)code— UInt64 code.UInt64
Tuple(UInt64)
Examples
Simple mode
Query
Response
Query
Response
Query
Response
Query
Response
mortonEncode
Introduced in: v24.6.0 Calculates the Morton encoding (ZCurve) for a list of unsigned integers. The function has two modes of operation:- Simple
- Expanded*
UInt64 code.
Expanded mode
Accepts a range mask (Tuple) as the first argument and
up to 8 unsigned integers as other arguments.
Each number in the mask configures the amount of range expansion:
- 1 - no expansion
- 2 - 2x expansion
- 3 - 3x expansion ⋮
- Up to 8x expansion.
args— Up to 8 unsigned integers or columns of the aforementioned type.UInt8/16/32/64range_mask— For the expanded mode, the mask for each argument. The mask is a tuple of unsigned integers from1-8. Each number in the mask configures the amount of range shrink.Tuple(UInt8/16/32/64)
UInt64 code. UInt64
Examples
Simple mode
Query
Response
Query
Response
Query
Response
Query
Response
Query
Response
sqidDecode
Introduced in: v24.1.0 Transforms a sqid back into an array of numbers. Syntaxsqid— The sqid to decode.String
sqid. Array(UInt64)
Examples
Usage example
Query
Response
sqidEncode
Introduced in: v24.1.0 Transforms numbers into a sqid, a Youtube-like ID string. Syntaxsqid
Arguments
n1[, n2, ...]— Arbitrarily many numbers.UInt8/16/32/64
String
Examples
Usage example
Query
Response
unbin
Introduced in: v21.8.0 Interprets each pair of binary digits (in the argument) as a number and converts it to the byte represented by the number. The functions performs the opposite operation to bin. For a numeric argumentunbin() does not return the inverse of bin(). If you want to convert the result to a number, you can use the reverse and reinterpretAs<Type> functions.
If
unbin is invoked from within the clickhouse-client, binary strings are displayed using UTF-8.0 and 1. The number of binary digits does not have to be multiples of eight. If the argument string contains anything other than binary digits,
the result is undefined (no exception is thrown).
Syntax
arg— A string containing any number of binary digits.String
String
Examples
Basic usage
Query
Response
Query
Response
unhex
Introduced in: v1.1.0 Performs the opposite operation ofhex. It interprets each pair of hexadecimal digits (in the argument) as a number and converts
it to the byte represented by the number. The returned 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.
clickhouse-client interprets strings as UTF-8.
This may cause that values returned by hex to be displayed surprisingly.A-F.
The number of hexadecimal digits does not have to be even.
If it is odd, the last digit is interpreted as the least significant half of the 00-0F byte.
If the argument string contains anything other than hexadecimal digits, some implementation-defined result is returned (an exception isn’t thrown).
For a numeric argument the inverse of hex(N) is not performed by unhex().
Syntax
arg— A string containing any number of hexadecimal digits.StringorFixedString
String
Examples
Basic usage
Query
Response
Query
Response