id
stringlengths
36
36
document
stringlengths
3
3k
metadata
stringlengths
23
69
embeddings
listlengths
384
384
bcee3442-d2e2-45db-97f3-bedd1cb6897a
ngramSearchCaseInsensitive {#ngramSearchCaseInsensitive} Introduced in: v20.1 Provides a case-insensitive variant of ngramSearch . Calculates the non-symmetric difference between a needle string and a haystack string, i.e. the number of n-grams from the needle minus the common number of n-grams normalized by the number of needle n-grams. Checks if the 4-gram distance between two strings is less than or equal to a given threshold, ignoring case. Syntax sql ngramSearchCaseInsensitive(haystack, needle) Arguments haystack — String for comparison. String needle — String for comparison. String Returned value Returns 1 if the 4-gram distance between the strings is less than or equal to a threshold ( 1.0 by default), 0 otherwise. UInt8 Examples Case-insensitive search using 4-grams sql title=Query SELECT ngramSearchCaseInsensitive('Hello World','hello') response title=Response ┌─ngramSearchCaseInsensitive('Hello World','hello')─┐ │ 1 │ └────────────────────────────────────────────────────┘ ngramSearchCaseInsensitiveUTF8 {#ngramSearchCaseInsensitiveUTF8} Introduced in: v20.1 Provides a case-insensitive UTF-8 variant of ngramSearch . Assumes haystack and needle to be UTF-8 strings and ignores case. Checks if the 3-gram distance between two UTF-8 strings is less than or equal to a given threshold, ignoring case. Syntax sql ngramSearchCaseInsensitiveUTF8(haystack, needle) Arguments haystack — UTF-8 string for comparison. String needle — UTF-8 string for comparison. String Returned value Returns 1 if the 3-gram distance between the strings is less than or equal to a threshold ( 1.0 by default), 0 otherwise. UInt8 Examples Case-insensitive UTF-8 search using 3-grams sql title=Query SELECT ngramSearchCaseInsensitiveUTF8('абвГДЕёжз', 'АбвгдЕЁжз') response title=Response ┌─ngramSearchCaseInsensitiveUTF8('абвГДЕёжз', 'АбвгдЕЁжз')─┐ │ 1 │ └──────────────────────────────────────────────────────────┘ ngramSearchUTF8 {#ngramSearchUTF8} Introduced in: v20.1 Provides a UTF-8 variant of ngramSearch . Assumes haystack and needle to be UTF-8 strings. Checks if the 3-gram distance between two UTF-8 strings is less than or equal to a given threshold. Syntax sql ngramSearchUTF8(haystack, needle) Arguments haystack — UTF-8 string for comparison. String needle — UTF-8 string for comparison. String Returned value Returns 1 if the 3-gram distance between the strings is less than or equal to a threshold ( 1.0 by default), 0 otherwise. UInt8 Examples UTF-8 search using 3-grams sql title=Query SELECT ngramSearchUTF8('абвгдеёжз', 'гдеёзд') response title=Response ┌─ngramSearchUTF8('абвгдеёжз', 'гдеёзд')─┐ │ 1 │ └────────────────────────────────────────┘ notILike {#notILike} Introduced in: v20.6
{"source_file": "string-search-functions.md"}
[ -0.032388895750045776, -0.025072505697607994, 0.028726322576403618, 0.004368110094219446, -0.07754485309123993, -0.024964313954114914, 0.004023048561066389, 0.06142609566450119, -0.07750306278467178, -0.0029126496519893408, 0.007224611937999725, -0.040954649448394775, 0.04648781940340996, ...
c1aa02bd-c63a-4f63-bcb6-922eb611d6ba
notILike {#notILike} Introduced in: v20.6 Checks whether a string does not match a pattern, case-insensitive. The pattern can contain special characters % and _ for SQL LIKE matching. Syntax sql notILike(haystack, pattern) Arguments haystack — The input string to search in. String or FixedString pattern — The SQL LIKE pattern to match against. % matches any number of characters (including zero), _ matches exactly one character. String Returned value Returns 1 if the string does not match the pattern (case-insensitive), otherwise 0 . UInt8 Examples Usage example sql title=Query SELECT notILike('ClickHouse', '%house%'); response title=Response ┌─notILike('Cl⋯ '%house%')─┐ │ 0 │ └──────────────────────────┘ notLike {#notLike} Introduced in: v1.1 Similar to like but negates the result. Syntax sql notLike(haystack, pattern) -- haystack NOT LIKE pattern Arguments haystack — String in which the search is performed. String or FixedString pattern — LIKE pattern to match against. String Returned value Returns 1 if the string does not match the LIKE pattern, otherwise 0 . UInt8 Examples Usage example sql title=Query SELECT notLike('ClickHouse', '%House%'); response title=Response ┌─notLike('Cli⋯ '%House%')─┐ │ 0 │ └──────────────────────────┘ Non-matching pattern sql title=Query SELECT notLike('ClickHouse', '%SQL%'); response title=Response ┌─notLike('Cli⋯', '%SQL%')─┐ │ 1 │ └──────────────────────────┘ position {#position} Introduced in: v1.1 Returns the position (in bytes, starting at 1) of a substring needle in a string haystack . If substring needle is empty, these rules apply: - if no start_pos was specified: return 1 - if start_pos = 0 : return 1 - if start_pos >= 1 and start_pos <= length(haystack) + 1 : return start_pos - otherwise: return 0 The same rules also apply to functions locate , positionCaseInsensitive , positionUTF8 and positionCaseInsensitiveUTF8 . Syntax sql position(haystack, needle[, start_pos]) Arguments haystack — String in which the search is performed. String or Enum needle — Substring to be searched. String start_pos — Position (1-based) in haystack at which the search starts. Optional. UInt Returned value Returns starting position in bytes and counting from 1, if the substring was found, otherwise 0 , if the substring was not found. UInt64 Examples Basic usage sql title=Query SELECT position('Hello, world!', '!') response title=Response ┌─position('Hello, world!', '!')─┐ │ 13 │ └────────────────────────────────┘ With start_pos argument sql title=Query SELECT position('Hello, world!', 'o', 1), position('Hello, world!', 'o', 7)
{"source_file": "string-search-functions.md"}
[ -0.017580213025212288, 0.00933905877172947, 0.0598612055182457, 0.034558407962322235, -0.0598350390791893, -0.0640023946762085, 0.07483924180269241, -0.012479312717914581, -0.03148876875638962, -0.0466763935983181, 0.06684104353189468, -0.06496546417474747, 0.12420055270195007, -0.07100604...
316a8311-5001-4b98-b8b2-be8c2e9662fb
With start_pos argument sql title=Query SELECT position('Hello, world!', 'o', 1), position('Hello, world!', 'o', 7) response title=Response ┌─position('Hello, world!', 'o', 1)─┬─position('Hello, world!', 'o', 7)─┐ │ 5 │ 9 │ └───────────────────────────────────┴───────────────────────────────────┘ Needle IN haystack syntax sql title=Query SELECT 6 = position('/' IN s) FROM (SELECT 'Hello/World' AS s) response title=Response ┌─equals(6, position(s, '/'))─┐ │ 1 │ └─────────────────────────────┘ Empty needle substring sql title=Query SELECT position('abc', ''), position('abc', '', 0), position('abc', '', 1), position('abc', '', 2), position('abc', '', 3), position('abc', '', 4), position('abc', '', 5) response title=Response ┌─position('abc', '')─┬─position('abc', '', 0)─┬─position('abc', '', 1)─┬─position('abc', '', 2)─┬─position('abc', '', 3)─┬─position('abc', '', 4)─┬─position('abc', '', 5)─┐ │ 1 │ 1 │ 1 │ 2 │ 3 │ 4 │ 0 │ └─────────────────────┴────────────────────────┴────────────────────────┴────────────────────────┴────────────────────────┴────────────────────────┴────────────────────────┘ positionCaseInsensitive {#positionCaseInsensitive} Introduced in: v1.1 Like position but case-insensitive. Syntax sql positionCaseInsensitive(haystack, needle[, start_pos]) Aliases : instr Arguments haystack — String in which the search is performed. String or Enum needle — Substring to be searched. String start_pos — Optional. Position (1-based) in haystack at which the search starts. UInt* Returned value Returns starting position in bytes and counting from 1, if the substring was found, otherwise 0 , if the substring was not found. UInt64 Examples Case insensitive search sql title=Query SELECT positionCaseInsensitive('Hello, world!', 'hello') response title=Response ┌─positionCaseInsensitive('Hello, world!', 'hello')─┐ │ 1 │ └───────────────────────────────────────────────────┘ positionCaseInsensitiveUTF8 {#positionCaseInsensitiveUTF8} Introduced in: v1.1 Like positionUTF8 but searches case-insensitively. Syntax sql positionCaseInsensitiveUTF8(haystack, needle[, start_pos]) Arguments haystack — String in which the search is performed. String or Enum needle — Substring to be searched. String start_pos — Optional. Position (1-based) in haystack at which the search starts. UInt* Returned value Returns starting position in bytes and counting from 1, if the substring was found, otherwise 0 , if the substring was not found. UInt64 Examples Case insensitive UTF-8 search sql title=Query SELECT positionCaseInsensitiveUTF8('Привет мир', 'МИР')
{"source_file": "string-search-functions.md"}
[ -0.02283327281475067, -0.013844636268913746, 0.024571115151047707, -0.0044083427637815475, -0.11373984813690186, -0.04385211691260338, 0.06493784487247467, 0.013386853970587254, -0.017387714236974716, 0.008177784271538258, 0.027795715257525444, 0.0008810725994408131, 0.07350455224514008, -...
622b0c09-f3f9-401e-a83a-6a1afa0ac61e
Examples Case insensitive UTF-8 search sql title=Query SELECT positionCaseInsensitiveUTF8('Привет мир', 'МИР') response title=Response ┌─positionCaseInsensitiveUTF8('Привет мир', 'МИР')─┐ │ 8 │ └──────────────────────────────────────────────────┘ positionUTF8 {#positionUTF8} Introduced in: v1.1 Like position but assumes haystack and needle are UTF-8 encoded strings. Syntax sql positionUTF8(haystack, needle[, start_pos]) Arguments haystack — String in which the search is performed. String or Enum needle — Substring to be searched. String start_pos — Optional. Position (1-based) in haystack at which the search starts. UInt* Returned value Returns starting position in bytes and counting from 1, if the substring was found, otherwise 0 , if the substring was not found. UInt64 Examples UTF-8 character counting sql title=Query SELECT positionUTF8('Motörhead', 'r') response title=Response ┌─position('Motörhead', 'r')─┐ │ 5 │ └────────────────────────────┘ regexpExtract {#regexpExtract} Introduced in: v Extracts the first string in haystack that matches the regexp pattern and corresponds to the regex group index. Syntax ```sql ``` Aliases : REGEXP_EXTRACT Arguments None. Returned value Examples
{"source_file": "string-search-functions.md"}
[ -0.006609524134546518, -0.034582480788230896, -0.003401742083951831, -0.009688964113593102, -0.08945927768945694, 0.0100918123498559, 0.0871858149766922, 0.06387101113796234, -0.00013331753143575042, -0.026492057368159294, 0.06582420319318771, 0.005745091009885073, 0.1151851937174797, -0.0...
fb83ce2b-3122-4627-8a25-2bb92e8ec7ff
description: 'Documentation for Hash Functions' sidebar_label: 'Hash' slug: /sql-reference/functions/hash-functions title: 'Hash Functions' doc_type: 'reference' Hash functions Hash functions can be used for the deterministic pseudo-random shuffling of elements. Simhash is a hash function, which returns close hash values for close (similar) arguments. Most hash functions accept any number of arguments of any types. :::note Hash of NULL is NULL. To get a non-NULL hash of a Nullable column, wrap it in a tuple: sql SELECT cityHash64(tuple(NULL)) ::: :::note To calculate hash of the whole contents of a table, use sum(cityHash64(tuple(*))) (or other hash function). tuple ensures that rows with NULL values are not skipped. sum ensures that the order of rows doesn't matter. ::: BLAKE3 {#BLAKE3} Introduced in: v22.10 Calculates BLAKE3 hash string and returns the resulting set of bytes as FixedString. This cryptographic hash-function is integrated into ClickHouse with BLAKE3 Rust library. The function is rather fast and shows approximately two times faster performance compared to SHA-2, while generating hashes of the same length as SHA-256. It returns a BLAKE3 hash as a byte array with type FixedString(32). Syntax sql BLAKE3(message) Arguments message — The input string to hash. String Returned value Returns the 32-byte BLAKE3 hash of the input string as a fixed-length string. FixedString(32) Examples hash sql title=Query SELECT hex(BLAKE3('ABC')) response title=Response ┌─hex(BLAKE3('ABC'))───────────────────────────────────────────────┐ │ D1717274597CF0289694F75D96D444B992A096F1AFD8E7BBFA6EBB1D360FEDFC │ └──────────────────────────────────────────────────────────────────┘ MD4 {#MD4} Introduced in: v21.11 Calculates the MD4 hash of the given string. Syntax sql MD4(s) Arguments s — The input string to hash. String Returned value Returns the MD4 hash of the given input string as a fixed-length string. FixedString(16) Examples Usage example sql title=Query SELECT HEX(MD4('abc')); response title=Response ┌─hex(MD4('abc'))──────────────────┐ │ A448017AAF21D8525FC10AE87AA6729D │ └──────────────────────────────────┘ MD5 {#MD5} Introduced in: v1.1 Calculates the MD5 hash of the given string. Syntax sql MD5(s) Arguments s — The input string to hash. String Returned value Returns the MD5 hash of the given input string as a fixed-length string. FixedString(16) Examples Usage example sql title=Query SELECT HEX(MD5('abc')); response title=Response ┌─hex(MD5('abc'))──────────────────┐ │ 900150983CD24FB0D6963F7D28E17F72 │ └──────────────────────────────────┘ RIPEMD160 {#RIPEMD160} Introduced in: v24.10 Calculates the RIPEMD-160 hash of the given string. Syntax sql RIPEMD160(s) Arguments s — The input string to hash. String Returned value
{"source_file": "hash-functions.md"}
[ 0.043515998870134354, 0.024205563589930534, -0.04681231454014778, -0.03962334245443344, -0.007591495756059885, -0.03717951104044914, 0.059119731187820435, -0.0664868950843811, -0.009637911804020405, 0.02762508951127529, 0.03648136183619499, 0.010538367554545403, 0.05939088761806488, -0.122...
65dbba4a-fcec-49b5-a92f-5b6660dbe5e4
Introduced in: v24.10 Calculates the RIPEMD-160 hash of the given string. Syntax sql RIPEMD160(s) Arguments s — The input string to hash. String Returned value Returns the RIPEMD160 hash of the given input string as a fixed-length string. FixedString(20) Examples Usage example sql title=Query SELECT HEX(RIPEMD160('The quick brown fox jumps over the lazy dog')); response title=Response ┌─HEX(RIPEMD160('The quick brown fox jumps over the lazy dog'))─┐ │ 37F332F68DB77BD9D7EDD4969571AD671CF9DD3B │ └───────────────────────────────────────────────────────────────┘ SHA1 {#SHA1} Introduced in: v1.1 Calculates the SHA1 hash of the given string. Syntax sql SHA1(s) Arguments s — The input string to hash String Returned value Returns the SHA1 hash of the given input string as a fixed-length string. FixedString(20) Examples Usage example sql title=Query SELECT HEX(SHA1('abc')); response title=Response ┌─hex(SHA1('abc'))─────────────────────────┐ │ A9993E364706816ABA3E25717850C26C9CD0D89D │ └──────────────────────────────────────────┘ SHA224 {#SHA224} Introduced in: v1.1 Calculates the SHA224 hash of the given string. Syntax sql SHA224(s) Arguments s — The input value to hash. String Returned value Returns the SHA224 hash of the given input string as a fixed-length string. FixedString(28) Examples Usage example sql title=Query SELECT HEX(SHA224('abc')); response title=Response ┌─hex(SHA224('abc'))───────────────────────────────────────┐ │ 23097D223405D8228642A477BDA255B32AADBCE4BDA0B3F7E36C9DA7 │ └──────────────────────────────────────────────────────────┘ SHA256 {#SHA256} Introduced in: v1.1 Calculates the SHA256 hash of the given string. Syntax sql SHA256(s) Arguments s — The input string to hash. String Returned value Returns the SHA256 hash of the given input string as a fixed-length string. FixedString(32) Examples Usage example sql title=Query SELECT HEX(SHA256('abc')); response title=Response ┌─hex(SHA256('abc'))───────────────────────────────────────────────┐ │ BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD │ └──────────────────────────────────────────────────────────────────┘ SHA384 {#SHA384} Introduced in: v1.1 Calculates the SHA384 hash of the given string. Syntax sql SHA384(s) Arguments s — The input string to hash. String Returned value Returns the SHA384 hash of the given input string as a fixed-length string. FixedString(48) Examples Usage example sql title=Query SELECT HEX(SHA384('abc')); response title=Response ┌─hex(SHA384('abc'))───────────────────────────────────────────────────────────────────────────────┐ │ CB00753F45A35E8BB5A03D699AC65007272C32AB0EDED1631A8B605A43FF5BED8086072BA1E7CC2358BAECA134C825A7 │ └──────────────────────────────────────────────────────────────────────────────────────────────────┘ SHA512 {#SHA512}
{"source_file": "hash-functions.md"}
[ 0.053569450974464417, 0.01846068724989891, -0.01790683902800083, -0.04489484056830406, -0.07979477941989899, -0.005560760386288166, 0.026694869622588158, 0.04494870454072952, 0.00431001465767622, 0.004552649799734354, 0.02967635542154312, 0.03650497645139694, 0.09451233595609665, -0.081537...
87017687-737f-4302-b7a9-6646005ccb9a
SHA512 {#SHA512} Introduced in: v1.1 Calculates the SHA512 hash of the given string. Syntax sql SHA512(s) Arguments s — The input string to hash String Returned value Returns the SHA512 hash of the given input string as a fixed-length string. FixedString(64) Examples Usage example sql title=Query SELECT HEX(SHA512('abc')); response title=Response ┌─hex(SHA512('abc'))───────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ DDAF35A193617ABACC417349AE20413112E6FA4E89A97EA20A9EEEE64B55D39A2192992A274FC1A836BA3C23A3FEEBBD454D4423643CE80E2A9AC94FA54CA49F │ └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ SHA512_256 {#SHA512_256} Introduced in: v1.1 Calculates the SHA512_256 hash of the given string. Syntax sql SHA512_256(s) Arguments s — The input string to hash. String Returned value Returns the SHA512_256 hash of the given input string as a fixed-length string. FixedString(32) Examples Usage example sql title=Query SELECT HEX(SHA512_256('abc')); response title=Response ┌─hex(SHA512_256('abc'))───────────────────────────────────────────┐ │ 53048E2681941EF99B2E29B76B4C7DABE4C2D0C634FC6D46E0E2F13107E7AF23 │ └──────────────────────────────────────────────────────────────────┘ URLHash {#URLHash} Introduced in: v1.1 A fast, decent-quality non-cryptographic hash function for a string obtained from a URL using some type of normalization. This hash function has two modes: | Mode | Description | |------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | URLHash(url) | Calculates a hash from a string without one of the trailing symbols / , ? or # at the end, if present. | | URLHash(url, N) | Calculates a hash from a string up to the N level in the URL hierarchy, without one of the trailing symbols / , ? or # at the end, if present. Levels are the same as in URLHierarchy .| Syntax sql URLHash(url[, N]) Arguments url — URL string to hash. String N — Optional. Level in the URL hierarchy. (U)Int* Returned value Returns the computed hash value of url . UInt64 Examples Usage example sql title=Query SELECT URLHash('https://www.clickhouse.com') response title=Response ┌─URLHash('htt⋯house.com')─┐ │ 13614512636072854701 │ └──────────────────────────┘ Hash of url with specified level
{"source_file": "hash-functions.md"}
[ 0.06639539450407028, 0.030533242970705032, -0.05296821519732475, -0.03956868499517441, -0.0850159302353859, 0.011607340537011623, 0.02955964021384716, 0.0223850030452013, -0.02626911923289299, -0.022072026506066322, 0.015890415757894516, 0.02743382193148136, 0.1206124871969223, -0.11242278...
82c5eceb-8a72-4f00-89f9-b7582b719cdf
response title=Response ┌─URLHash('htt⋯house.com')─┐ │ 13614512636072854701 │ └──────────────────────────┘ Hash of url with specified level sql title=Query SELECT URLHash('https://www.clickhouse.com/docs', 0); SELECT URLHash('https://www.clickhouse.com/docs', 1); response title=Response -- hash of https://www.clickhouse.com ┌─URLHash('htt⋯m/docs', 0)─┐ │ 13614512636072854701 │ └──────────────────────────┘ -- hash of https://www.clickhouse.com/docs ┌─URLHash('htt⋯m/docs', 1)─┐ │ 13167253331440520598 │ └──────────────────────────┘ cityHash64 {#cityHash64} Introduced in: v1.1 Produces a 64-bit CityHash hash value. This is a fast non-cryptographic hash function. It uses the CityHash algorithm for string parameters and implementation-specific fast non-cryptographic hash function for parameters with other data types. The function uses the CityHash combinator to get the final results. :::info Google changed the algorithm of CityHash after it was added to ClickHouse. In other words, ClickHouse's cityHash64 and Google's upstream CityHash now produce different results. ClickHouse cityHash64 corresponds to CityHash v1.0.2. ::: :::note The calculated hash values may be equal for the same input values of different argument types. This affects for example integer types of different size, named and unnamed Tuple with the same data, Map and the corresponding Array(Tuple(key, value)) type with the same data. ::: Syntax sql cityHash64(arg1[, arg2, ...]) Arguments arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any Returned value Returns the computed hash of the input arguments. UInt64 Examples Call example sql title=Query SELECT cityHash64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS CityHash, toTypeName(CityHash) AS type; response title=Response ┌─────────────CityHash─┬─type───┐ │ 12072650598913549138 │ UInt64 │ └──────────────────────┴────────┘ Computing the checksum of the entire table with accuracy up to the row order ```sql title=Query CREATE TABLE users ( id UInt32, name String, age UInt8, city String ) ENGINE = MergeTree ORDER BY tuple(); INSERT INTO users VALUES (1, 'Alice', 25, 'New York'), (2, 'Bob', 30, 'London'), (3, 'Charlie', 35, 'Tokyo'); SELECT groupBitXor(cityHash64(*)) FROM users; ``` response title=Response ┌─groupBitXor(⋯age, city))─┐ │ 11639977218258521182 │ └──────────────────────────┘ farmFingerprint64 {#farmFingerprint64} Introduced in: v20.12 Produces a 64-bit FarmHash value using the Fingerprint64 method. :::tip farmFingerprint64 is preferred for a stable and portable value over farmHash64 . :::
{"source_file": "hash-functions.md"}
[ 0.019058046862483025, 0.05752203240990639, 0.025785451754927635, -0.02471388503909111, -0.04054120182991028, -0.10095079988241196, -0.017387617379426956, -0.08458739519119263, 0.05244608223438263, 0.013390268199145794, 0.012332496233284473, -0.03162837773561478, 0.03567422181367874, -0.058...
2c4c8d1f-54cc-4e32-99db-405a2bd8d96a
Introduced in: v20.12 Produces a 64-bit FarmHash value using the Fingerprint64 method. :::tip farmFingerprint64 is preferred for a stable and portable value over farmHash64 . ::: :::note The calculated hash values may be equal for the same input values of different argument types. This affects for example integer types of different size, named and unnamed Tuple with the same data, Map and the corresponding Array(Tuple(key, value)) type with the same data. ::: Syntax sql farmFingerprint64(arg1[, arg2, ...]) Arguments arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any Returned value Returns the computed hash value of the input arguments. UInt64 Examples Usage example sql title=Query SELECT farmFingerprint64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS FarmFingerprint, toTypeName(FarmFingerprint) AS type; response title=Response ┌─────FarmFingerprint─┬─type───┐ │ 5752020380710916328 │ UInt64 │ └─────────────────────┴────────┘ farmHash64 {#farmHash64} Introduced in: v1.1 Produces a 64-bit FarmHash using the Hash64 method. :::tip farmFingerprint64 is preferred for a stable and portable value. ::: :::note The calculated hash values may be equal for the same input values of different argument types. This affects for example integer types of different size, named and unnamed Tuple with the same data, Map and the corresponding Array(Tuple(key, value)) type with the same data. ::: Syntax sql farmHash64(arg1[, arg2, ...]) Arguments arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any Returned value Returns the computed hash value of the input arguments. UInt64 Examples Usage example sql title=Query SELECT farmHash64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS FarmHash, toTypeName(FarmHash) AS type; response title=Response ┌─────────────FarmHash─┬─type───┐ │ 18125596431186471178 │ UInt64 │ └──────────────────────┴────────┘ gccMurmurHash {#gccMurmurHash} Introduced in: v20.1 Computes the 64-bit MurmurHash2 hash of the input value using the same seed as used by GCC . It is portable between Clang and GCC builds. Syntax sql gccMurmurHash(arg1[, arg2, ...]) Arguments arg1[, arg2, ...] — A variable number of arguments for which to compute the hash. Any Returned value Returns the calculated hash value of the input arguments. UInt64 Examples Usage example sql title=Query SELECT gccMurmurHash(1, 2, 3) AS res1, gccMurmurHash(('a', [1, 2, 3], 4, (4, ['foo', 'bar'], 1, (1, 2)))) AS res2 response title=Response ┌─────────────────res1─┬────────────────res2─┐ │ 12384823029245979431 │ 1188926775431157506 │ └──────────────────────┴─────────────────────┘ halfMD5 {#halfMD5} Introduced in: v1.1
{"source_file": "hash-functions.md"}
[ 0.021871019154787064, 0.05314036086201668, -0.074677973985672, -0.04131321609020233, -0.025051061064004898, -0.04028605297207832, 0.010501982644200325, -0.019473839551210403, -0.041163623332977295, 0.010402857325971127, 0.033178411424160004, 0.043840330094099045, 0.030821532011032104, -0.0...
afeccb50-5822-48fc-871d-01dabfe52740
halfMD5 {#halfMD5} Introduced in: v1.1 Interprets all the input parameters as strings and calculates the MD5 hash value for each of them. Then combines hashes, takes the first 8 bytes of the hash of the resulting string, and interprets them as UInt64 in big-endian byte order. The function is relatively slow (5 million short strings per second per processor core). Consider using the sipHash64 function instead. The function takes a variable number of input parameters. Arguments can be any of the supported data types. For some data types calculated value of hash function may be the same for the same values even if types of arguments differ (integers of different size, named and unnamed Tuple with the same data, Map and the corresponding Array(Tuple(key, value)) type with the same data). Syntax sql halfMD5(arg1[, arg2, ..., argN]) Arguments arg1[, arg2, ..., argN] — Variable number of arguments for which to compute the hash. Any Returned value Returns the computed half MD5 hash of the given input params returned as a UInt64 in big-endian byte order. UInt64 Examples Usage example sql title=Query SELECT HEX(halfMD5('abc', 'cde', 'fgh')); response title=Response ┌─hex(halfMD5('abc', 'cde', 'fgh'))─┐ │ 2C9506B7374CFAF4 │ └───────────────────────────────────┘ hiveHash {#hiveHash} Introduced in: v20.1 Calculates a "HiveHash" from a string. This is just JavaHash with zeroed out sign bits. This function is used in Apache Hive for versions before 3.0. :::caution This hash function is unperformant. Use it only when this algorithm is already used in another system and you need to calculate the same result. ::: Syntax sql hiveHash(arg) Arguments arg — Input string to hash. String Returned value Returns the computed "hive hash" of the input string. Int32 Examples Usage example sql title=Query SELECT hiveHash('Hello, world!'); response title=Response ┌─hiveHash('Hello, world!')─┐ │ 267439093 │ └───────────────────────────┘ intHash32 {#intHash32} Introduced in: v1.1 Calculates a 32-bit hash of an integer. The hash function is relatively fast but not cryptographic hash function. Syntax sql intHash32(arg) Arguments arg — Integer to hash. (U)Int* Returned value Returns the computed 32-bit hash code of the input integer UInt32 Examples Usage example sql title=Query SELECT intHash32(42); response title=Response ┌─intHash32(42)─┐ │ 1228623923 │ └───────────────┘ intHash64 {#intHash64} Introduced in: v1.1 Calculates a 64-bit hash of an integer. The hash function is relatively fast (even faster than intHash32 ) but not a cryptographic hash function. Syntax sql intHash64(int) Arguments int — Integer to hash. (U)Int* Returned value 64-bit hash code. UInt64 Examples Usage example sql title=Query SELECT intHash64(42);
{"source_file": "hash-functions.md"}
[ 0.03709688410162926, -0.007183631416410208, 0.04413118585944176, -0.07108338922262192, -0.021907219663262367, -0.12081685662269592, -0.02504371851682663, 0.016077138483524323, -0.08006413280963898, 0.055938608944416046, -0.07685846090316772, 0.03206987679004669, 0.023516211658716202, -0.05...
ff62a13b-5c41-47c9-ab16-64adc643b81e
Syntax sql intHash64(int) Arguments int — Integer to hash. (U)Int* Returned value 64-bit hash code. UInt64 Examples Usage example sql title=Query SELECT intHash64(42); response title=Response ┌────────intHash64(42)─┐ │ 11490350930367293593 │ └──────────────────────┘ javaHash {#javaHash} Introduced in: v20.1 Calculates JavaHash from: - string , - Byte , - Short , - Integer , - Long . :::caution This hash function is unperformant. Use it only when this algorithm is already in use in another system and you need to calculate the same result. ::: :::note Java only supports calculating the hash of signed integers, so if you want to calculate a hash of unsigned integers you must cast them to the proper signed ClickHouse types. ::: Syntax sql javaHash(arg) Arguments arg — Input value to hash. Any Returned value Returns the computed hash of arg Int32 Examples Usage example 1 sql title=Query SELECT javaHash(toInt32(123)); response title=Response ┌─javaHash(toInt32(123))─┐ │ 123 │ └────────────────────────┘ Usage example 2 sql title=Query SELECT javaHash('Hello, world!'); response title=Response ┌─javaHash('Hello, world!')─┐ │ -1880044555 │ └───────────────────────────┘ javaHashUTF16LE {#javaHashUTF16LE} Introduced in: v20.1 Calculates JavaHash from a string, assuming it contains bytes representing a string in UTF-16LE encoding. Syntax sql javaHashUTF16LE(arg) Arguments arg — A string in UTF-16LE encoding. String Returned value Returns the computed hash of the UTF-16LE encoded string. Int32 Examples Usage example sql title=Query SELECT javaHashUTF16LE(convertCharset('test', 'utf-8', 'utf-16le')); response title=Response ┌─javaHashUTF16LE(convertCharset('test', 'utf-8', 'utf-16le'))─┐ │ 3556498 │ └──────────────────────────────────────────────────────────────┘ jumpConsistentHash {#jumpConsistentHash} Introduced in: v1.1 Calculates the jump consistent hash for an integer. Syntax sql jumpConsistentHash(key, buckets) Arguments key — The input key. UInt64 buckets — The number of buckets. Int32 Returned value Returns the computed hash value. Int32 Examples Usage example sql title=Query SELECT jumpConsistentHash(256, 4) response title=Response ┌─jumpConsistentHash(256, 4)─┐ │ 3 │ └────────────────────────────┘ kafkaMurmurHash {#kafkaMurmurHash} Introduced in: v23.4 Calculates the 32-bit MurmurHash2 hash of the input value using the same seed as used by Kafka and without the highest bit to be compatible with Default Partitioner . Syntax sql kafkaMurmurHash(arg1[, arg2, ...]) Arguments arg1[, arg2, ...] — A variable number of parameters for which to compute the hash. Any Returned value Returns the calculated hash value of the input arguments. UInt32 Examples Usage example
{"source_file": "hash-functions.md"}
[ 0.05947931110858917, 0.05646967515349388, -0.03872627392411232, -0.0361366830766201, -0.11253703385591507, -0.024679649621248245, 0.0645425021648407, 0.05956360697746277, -0.04699624702334404, 0.011707966215908527, -0.0870198979973793, -0.020268019288778305, 0.06478078663349152, -0.0498244...
9a6e8c6d-163e-4bfe-ae95-9f1e8db0216b
Returned value Returns the calculated hash value of the input arguments. UInt32 Examples Usage example sql title=Query SELECT kafkaMurmurHash('foobar') AS res1, kafkaMurmurHash(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS res2 response title=Response ┌───────res1─┬─────res2─┐ │ 1357151166 │ 85479775 │ └────────────┴──────────┘ keccak256 {#keccak256} Introduced in: v25.4 Calculates the Keccak-256 cryptographic hash of the given string. This hash function is widely used in blockchain applications, particularly Ethereum. Syntax sql keccak256(message) Arguments message — The input string to hash. String Returned value Returns the 32-byte Keccak-256 hash of the input string as a fixed-length string. FixedString(32) Examples Usage example sql title=Query SELECT hex(keccak256('hello')) response title=Response ┌─hex(keccak256('hello'))──────────────────────────────────────────┐ │ 1C8AFF950685C2ED4BC3174F3472287B56D9517B9C948127319A09A7A36DEAC8 │ └──────────────────────────────────────────────────────────────────┘ kostikConsistentHash {#kostikConsistentHash} Introduced in: v22.6 An O(1) time and space consistent hash algorithm by Konstantin 'Kostik' Oblakov. Only efficient with n <= 32768 . Syntax sql kostikConsistentHash(input, n) Aliases : yandexConsistentHash Arguments input — An integer key. UInt64 n — The number of buckets. UInt16 Returned value Returns the computed hash value. UInt16 Examples Usage example sql title=Query SELECT kostikConsistentHash(16045690984833335023, 2); response title=Response ┌─kostikConsistentHash(16045690984833335023, 2)─┐ │ 1 │ └───────────────────────────────────────────────┘ metroHash64 {#metroHash64} Introduced in: v1.1 Produces a 64-bit MetroHash hash value. :::note The calculated hash values may be equal for the same input values of different argument types. This affects for example integer types of different size, named and unnamed Tuple with the same data, Map and the corresponding Array(Tuple(key, value)) type with the same data. ::: Syntax sql metroHash64(arg1[, arg2, ...]) Arguments arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any Returned value Returns the computed hash of the input arguments. UInt64 Examples Usage example sql title=Query SELECT metroHash64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS MetroHash, toTypeName(MetroHash) AS type; response title=Response ┌────────────MetroHash─┬─type───┐ │ 14235658766382344533 │ UInt64 │ └──────────────────────┴────────┘ murmurHash2_32 {#murmurHash2_32} Introduced in: v18.5 Computes the MurmurHash2 hash of the input value.
{"source_file": "hash-functions.md"}
[ 0.0006645437097176909, 0.053550928831100464, -0.08654162287712097, -0.03266502544283867, -0.1064816489815712, -0.007926464080810547, 0.03701530024409294, 0.0262469295412302, 0.06839824467897415, 0.0011074419599026442, -0.032769400626420975, -0.0440128892660141, 0.01468364056199789, -0.1036...
aaf3d331-764a-4fd9-9156-19b6acb959ad
murmurHash2_32 {#murmurHash2_32} Introduced in: v18.5 Computes the MurmurHash2 hash of the input value. :::note The calculated hash values may be equal for the same input values of different argument types. This affects for example integer types of different size, named and unnamed Tuple with the same data, Map and the corresponding Array(Tuple(key, value)) type with the same data. ::: Syntax sql murmurHash2_32(arg1[, arg2, ...]) Arguments arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any Returned value Returns the computed hash value of the input arguments. UInt32 Examples Usage example sql title=Query SELECT murmurHash2_32(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS MurmurHash2, toTypeName(MurmurHash2) AS type; response title=Response ┌─MurmurHash2─┬─type───┐ │ 3681770635 │ UInt32 │ └─────────────┴────────┘ murmurHash2_64 {#murmurHash2_64} Introduced in: v18.10 Computes the MurmurHash2 hash of the input value. :::note The calculated hash values may be equal for the same input values of different argument types. This affects for example integer types of different size, named and unnamed Tuple with the same data, Map and the corresponding Array(Tuple(key, value)) type with the same data. ::: Syntax sql murmurHash2_64(arg1[, arg2, ...]) Arguments arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any Returned value Returns the computed hash of the input arguments. UInt64 Examples Usage example sql title=Query SELECT murmurHash2_64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS MurmurHash2, toTypeName(MurmurHash2) AS type; response title=Response ┌──────────MurmurHash2─┬─type───┐ │ 11832096901709403633 │ UInt64 │ └──────────────────────┴────────┘ murmurHash3_128 {#murmurHash3_128} Introduced in: v18.10 Computes the 128-bit MurmurHash3 hash of the input value. Syntax sql murmurHash3_128(arg1[, arg2, ...]) Arguments arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any Returned value Returns the computed 128-bit MurmurHash3 hash value of the input arguments. FixedString(16) Examples Usage example sql title=Query SELECT hex(murmurHash3_128('foo', 'foo', 'foo')); response title=Response ┌─hex(murmurHash3_128('foo', 'foo', 'foo'))─┐ │ F8F7AD9B6CD4CF117A71E277E2EC2931 │ └───────────────────────────────────────────┘ murmurHash3_32 {#murmurHash3_32} Introduced in: v18.10 Produces a MurmurHash3 hash value. :::note The calculated hash values may be equal for the same input values of different argument types. This affects for example integer types of different size, named and unnamed Tuple with the same data, Map and the corresponding Array(Tuple(key, value)) type with the same data. ::: Syntax sql murmurHash3_32(arg1[, arg2, ...]) Arguments
{"source_file": "hash-functions.md"}
[ 0.008429045788943768, -0.03732210397720337, 0.0062540373764932156, -0.03612574189901352, -0.11706149578094482, -0.0412805937230587, 0.03219054266810417, -0.06163341552019119, 0.048254918307065964, -0.03330809250473976, -0.038512375205755234, -0.01124432124197483, 0.03194602206349373, -0.05...
01054245-bddf-46b8-9643-2f29200a2c0b
Syntax sql murmurHash3_32(arg1[, arg2, ...]) Arguments arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any Returned value Returns the computed hash value of the input arguments. UInt32 Examples Usage example sql title=Query SELECT murmurHash3_32(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS MurmurHash3, toTypeName(MurmurHash3) AS type; response title=Response ┌─MurmurHash3─┬─type───┐ │ 2152717 │ UInt32 │ └─────────────┴────────┘ murmurHash3_64 {#murmurHash3_64} Introduced in: v18.10 Computes the MurmurHash3 hash of the input value. :::note The calculated hash values may be equal for the same input values of different argument types. This affects for example integer types of different size, named and unnamed Tuple with the same data, Map and the corresponding Array(Tuple(key, value)) type with the same data. ::: Syntax sql murmurHash3_64(arg1[, arg2, ...]) Arguments arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any Returned value Returns the computed hash value of the input arguments. UInt64 Examples Usage example sql title=Query SELECT murmurHash3_64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS MurmurHash3, toTypeName(MurmurHash3) AS type; response title=Response ┌──────────MurmurHash3─┬─type───┐ │ 11832096901709403633 │ UInt64 │ └──────────────────────┴────────┘ ngramMinHash {#ngramMinHash} Introduced in: v21.1 Splits a ASCII string into n-grams of ngramsize symbols and calculates hash values for each n-gram and returns a tuple with these hashes. Uses hashnum minimum hashes to calculate the minimum hash and hashnum maximum hashes to calculate the maximum hash. It is case sensitive. Can be used to detect semi-duplicate strings with tupleHammingDistance . For two strings, if the returned hashes are the same for both strings, then those strings are the same. Syntax sql ngramMinHash(string[, ngramsize, hashnum]) Arguments string — String for which to compute the hash. String ngramsize — Optional. The size of an n-gram, any number from 1 to 25 . The default value is 3 . UInt8 hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25 . The default value is 6 . UInt8 Returned value Returns a tuple with two hashes — the minimum and the maximum. Tuple Examples Usage example sql title=Query SELECT ngramMinHash('ClickHouse') AS Tuple; response title=Response ┌─Tuple──────────────────────────────────────┐ │ (18333312859352735453,9054248444481805918) │ └────────────────────────────────────────────┘ ngramMinHashArg {#ngramMinHashArg} Introduced in: v21.1
{"source_file": "hash-functions.md"}
[ 0.005757139064371586, -0.027769457548856735, -0.014396026730537415, -0.03870686888694763, -0.0952632948756218, -0.030633797869086266, 0.06656457483768463, -0.06649962067604065, 0.048964083194732666, -0.019641490653157234, -0.057377882301807404, 0.0007751848897896707, 0.030696427449584007, ...
ecbd730b-293b-4186-8e34-5c64f8a0687e
ngramMinHashArg {#ngramMinHashArg} Introduced in: v21.1 Splits a ASCII string into n-grams of ngramsize symbols and returns the n-grams with minimum and maximum hashes, calculated by the ngramMinHash function with the same input. It is case sensitive. Syntax sql ngramMinHashArg(string[, ngramsize, hashnum]) Arguments string — String for which to compute the hash. String ngramsize — Optional. The size of an n-gram, any number from 1 to 25 . The default value is 3 . UInt8 hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25 . The default value is 6 . UInt8 Returned value Returns a tuple with two tuples with hashnum n-grams each. Tuple(String) Examples Usage example sql title=Query SELECT ngramMinHashArg('ClickHouse') AS Tuple; response title=Response ┌─Tuple─────────────────────────────────────────────────────────────────────────┐ │ (('ous','ick','lic','Hou','kHo','use'),('Hou','lic','ick','ous','ckH','Cli')) │ └───────────────────────────────────────────────────────────────────────────────┘ ngramMinHashArgCaseInsensitive {#ngramMinHashArgCaseInsensitive} Introduced in: v21.1 Splits a ASCII string into n-grams of ngramsize symbols and returns the n-grams with minimum and maximum hashes, calculated by the ngramMinHashCaseInsensitive function with the same input. It is case insensitive. Syntax sql ngramMinHashArgCaseInsensitive(string[, ngramsize, hashnum]) Arguments string — String for which to compute the hash. String ngramsize — Optional. The size of an n-gram, any number from 1 to 25 . The default value is 3 . UInt8 hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25 . The default value is 6 . UInt8 Returned value Returns a tuple with two tuples with hashnum n-grams each. Tuple(Tuple(String)) Examples Usage example sql title=Query SELECT ngramMinHashArgCaseInsensitive('ClickHouse') AS Tuple; response title=Response ┌─Tuple─────────────────────────────────────────────────────────────────────────┐ │ (('ous','ick','lic','kHo','use','Cli'),('kHo','lic','ick','ous','ckH','Hou')) │ └───────────────────────────────────────────────────────────────────────────────┘ ngramMinHashArgCaseInsensitiveUTF8 {#ngramMinHashArgCaseInsensitiveUTF8} Introduced in: v21.1 Splits a UTF-8 string into n-grams of ngramsize symbols and returns the n-grams with minimum and maximum hashes, calculated by the ngramMinHashCaseInsensitiveUTF8 function with the same input. It is case insensitive. Syntax sql ngramMinHashArgCaseInsensitiveUTF8(string[, ngramsize, hashnum]) Arguments string — String for which to compute the hash. String ngramsize — Optional. The size of an n-gram, any number from 1 to 25 . The default value is 3 . UInt8
{"source_file": "hash-functions.md"}
[ -0.010884849354624748, -0.02220364287495613, -0.028111577033996582, -0.04166952520608902, -0.07390781491994858, 0.018089409917593002, 0.06489989161491394, 0.07200363278388977, -0.02076655812561512, 0.02846568636596203, -0.0061760940589010715, 0.010188660584390163, 0.02193620055913925, -0.0...
e747e6f3-762f-42c7-ae2c-f6f5b938d56a
Arguments string — String for which to compute the hash. String ngramsize — Optional. The size of an n-gram, any number from 1 to 25 . The default value is 3 . UInt8 hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25 . The default value is 6 . UInt8 Returned value Returns a tuple with two tuples with hashnum n-grams each. Tuple(Tuple(String)) Examples Usage example sql title=Query SELECT ngramMinHashArgCaseInsensitiveUTF8('ClickHouse') AS Tuple; response title=Response ┌─Tuple─────────────────────────────────────────────────────────────────────────┐ │ (('ckH','ous','ick','lic','kHo','use'),('kHo','lic','ick','ous','ckH','Hou')) │ └───────────────────────────────────────────────────────────────────────────────┘ ngramMinHashArgUTF8 {#ngramMinHashArgUTF8} Introduced in: v21.1 Splits a UTF-8 string into n-grams of ngramsize symbols and returns the n-grams with minimum and maximum hashes, calculated by the ngramMinHashUTF8 function with the same input. It is case sensitive. Syntax sql ngramMinHashArgUTF8(string[, ngramsize, hashnum]) Arguments string — String for which to compute the hash. String ngramsize — Optional. The size of an n-gram, any number from 1 to 25 . The default value is 3 . UInt8 hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25 . The default value is 6 . UInt8 Returned value Returns a tuple with two tuples with hashnum n-grams each. Tuple(Tuple(String)) Examples Usage example sql title=Query SELECT ngramMinHashArgUTF8('ClickHouse') AS Tuple; response title=Response ┌─Tuple─────────────────────────────────────────────────────────────────────────┐ │ (('ous','ick','lic','Hou','kHo','use'),('kHo','Hou','lic','ick','ous','ckH')) │ └───────────────────────────────────────────────────────────────────────────────┘ ngramMinHashCaseInsensitive {#ngramMinHashCaseInsensitive} Introduced in: v21.1 Splits a ASCII string into n-grams of ngramsize symbols and calculates hash values for each n-gram and returns a tuple with these hashes Uses hashnum minimum hashes to calculate the minimum hash and hashnum maximum hashes to calculate the maximum hash. It is case insensitive. Can be used to detect semi-duplicate strings with tupleHammingDistance . For two strings, if the returned hashes are the same for both strings, then those strings are the same. Syntax sql ngramMinHashCaseInsensitive(string[, ngramsize, hashnum]) Arguments string — String. String . - ngramsize — The size of an n-gram. Optional. Possible values: any number from 1 to 25 . Default value: 3 . UInt8 . - hashnum — The number of minimum and maximum hashes used to calculate the result. Optional. Possible values: any number from 1 to 25 . Default value: 6 . UInt8 . Returned value
{"source_file": "hash-functions.md"}
[ -0.009927118197083473, 0.011105113662779331, -0.01584126427769661, -0.031692422926425934, -0.07276605814695358, 0.02105897106230259, 0.08267360180616379, 0.04850511625409126, 0.009026548825204372, 0.008961254730820656, 0.006039637606590986, -0.017899373546242714, 0.01709633693099022, -0.05...
fc7588ce-c81a-48e3-be05-b313330a6126
Returned value Tuple with two hashes — the minimum and the maximum. Tuple ( UInt64 , UInt64 ). Tuple Examples Usage example sql title=Query SELECT ngramMinHashCaseInsensitive('ClickHouse') AS Tuple; response title=Response ┌─Tuple──────────────────────────────────────┐ │ (2106263556442004574,13203602793651726206) │ └────────────────────────────────────────────┘ ngramMinHashCaseInsensitiveUTF8 {#ngramMinHashCaseInsensitiveUTF8} Introduced in: v21.1 Splits a UTF-8 string into n-grams of ngramsize symbols and calculates hash values for each n-gram and returns a tuple with these hashes.. Uses hashnum minimum hashes to calculate the minimum hash and hashnum maximum hashes to calculate the maximum hash. It is case insensitive. Can be used to detect semi-duplicate strings with tupleHammingDistance . For two strings, if the returned hashes are the same for both strings, then those strings are the same. Syntax sql ngramMinHashCaseInsensitiveUTF8(string [, ngramsize, hashnum]) Arguments string — String for which to compute the hash. String ngramsize — Optional. The size of an n-gram, any number from 1 to 25 . The default value is 3 . UInt8 hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25 . The default value is 6 . UInt8 Returned value Returns a tuple with two hashes — the minimum and the maximum. Tuple Examples Usage example sql title=Query SELECT ngramMinHashCaseInsensitiveUTF8('ClickHouse') AS Tuple; response title=Response ┌─Tuple───────────────────────────────────────┐ │ (12493625717655877135,13203602793651726206) │ └─────────────────────────────────────────────┘ ngramMinHashUTF8 {#ngramMinHashUTF8} Introduced in: v21.1 Splits a UTF-8 string into n-grams of ngramsize symbols and calculates hash values for each n-gram and returns a tuple with these hashes. Uses hashnum minimum hashes to calculate the minimum hash and hashnum maximum hashes to calculate the maximum hash. It is case sensitive. Can be used to detect semi-duplicate strings with tupleHammingDistance . For two strings, if the returned hashes are the same for both strings, then those strings are the same. Syntax sql ngramMinHashUTF8(string[, ngramsize, hashnum]) Arguments string — String for which to compute the hash. String ngramsize — Optional. The size of an n-gram, any number from 1 to 25 . The default value is 3 . UInt8 hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25 . The default value is 6 . UInt8 Returned value Returns a tuple with two hashes — the minimum and the maximum. Tuple Examples Usage example sql title=Query SELECT ngramMinHashUTF8('ClickHouse') AS Tuple;
{"source_file": "hash-functions.md"}
[ -0.01593576744198799, -0.05711788311600685, 0.004066769033670425, -0.043680693954229355, -0.0552801638841629, -0.005862010642886162, 0.06618640571832657, 0.03986075147986412, -0.03477616608142853, 0.0041299001313745975, -0.012491569854319096, 0.011358357965946198, 0.07247935235500336, -0.0...
22b9b88f-fbdc-4ae7-982c-45a2a54556d7
Returned value Returns a tuple with two hashes — the minimum and the maximum. Tuple Examples Usage example sql title=Query SELECT ngramMinHashUTF8('ClickHouse') AS Tuple; response title=Response ┌─Tuple──────────────────────────────────────┐ │ (18333312859352735453,6742163577938632877) │ └────────────────────────────────────────────┘ ngramSimHash {#ngramSimHash} Introduced in: v21.1 Splits a ASCII string into n-grams of ngramsize symbols and returns the n-gram simhash . Can be used for detection of semi-duplicate strings with bitHammingDistance . The smaller the Hamming distance of the calculated simhashes of two strings, the more likely these strings are the same. Syntax sql ngramSimHash(string[, ngramsize]) Arguments string — String for which to compute the case sensitive simhash . String ngramsize — Optional. The size of an n-gram, any number from 1 to 25 . The default value is 3 . UInt8 Returned value Returns the computed hash of the input string. UInt64 Examples Usage example sql title=Query SELECT ngramSimHash('ClickHouse') AS Hash; response title=Response ┌───────Hash─┐ │ 1627567969 │ └────────────┘ ngramSimHashCaseInsensitive {#ngramSimHashCaseInsensitive} Introduced in: v21.1 Splits a ASCII string into n-grams of ngramsize symbols and returns the n-gram simhash . It is case insensitive. Can be used for detection of semi-duplicate strings with bitHammingDistance . The smaller the Hamming distance of the calculated simhashes of two strings, the more likely these strings are the same. Syntax sql ngramSimHashCaseInsensitive(string[, ngramsize]) Arguments string — String for which to compute the case insensitive simhash . String ngramsize — Optional. The size of an n-gram, any number from 1 to 25 . The default value is 3 . UInt8 Returned value Hash value. UInt64 . UInt64 Examples Usage example sql title=Query SELECT ngramSimHashCaseInsensitive('ClickHouse') AS Hash; response title=Response ┌──────Hash─┐ │ 562180645 │ └───────────┘ ngramSimHashCaseInsensitiveUTF8 {#ngramSimHashCaseInsensitiveUTF8} Introduced in: v21.1 Splits a UTF-8 string into n-grams of ngramsize symbols and returns the n-gram simhash . It is case insensitive. Can be used for detection of semi-duplicate strings with bitHammingDistance . The smaller is the Hamming Distance of the calculated simhashes of two strings, the more likely these strings are the same. Syntax sql ngramSimHashCaseInsensitiveUTF8(string[, ngramsize]) Arguments string — String for which to compute the hash. String ngramsize — Optional. The size of an n-gram, any number from 1 to 25 . The default value is 3 . UInt8 Returned value Returns the computed hash value. UInt64 Examples Usage example sql title=Query SELECT ngramSimHashCaseInsensitiveUTF8('ClickHouse') AS Hash; response title=Response ┌───────Hash─┐ │ 1636742693 │ └────────────┘
{"source_file": "hash-functions.md"}
[ -0.020865805447101593, -0.05275265872478485, -0.05531108379364014, -0.01834048517048359, -0.10918757319450378, -0.019015472382307053, 0.0762176662683487, 0.03442646935582161, -0.03690400719642639, 0.00035679759457707405, -0.010263558477163315, -0.00884187500923872, 0.04986194893717766, -0....
38c53520-eea1-474a-b2a6-132dfc642cdc
Examples Usage example sql title=Query SELECT ngramSimHashCaseInsensitiveUTF8('ClickHouse') AS Hash; response title=Response ┌───────Hash─┐ │ 1636742693 │ └────────────┘ ngramSimHashUTF8 {#ngramSimHashUTF8} Introduced in: v21.1 Splits a UTF-8 encoded string into n-grams of ngramsize symbols and returns the n-gram simhash . It is case sensitive. Can be used for detection of semi-duplicate strings with bitHammingDistance . The smaller the Hamming distance of the calculated simhashes of two strings, the more likely these strings are the same. Syntax sql ngramSimHashUTF8(string[, ngramsize]) Arguments string — String for which to compute the hash. String ngramsize — Optional. The size of an n-gram, any number from 1 to 25 . The default value is 3 . UInt8 Returned value Returns the computed hash value. UInt64 Examples Usage example sql title=Query SELECT ngramSimHashUTF8('ClickHouse') AS Hash; response title=Response ┌───────Hash─┐ │ 1628157797 │ └────────────┘ sipHash128 {#sipHash128} Introduced in: v1.1 Like sipHash64 but produces a 128-bit hash value, i.e. the final xor-folding state is done up to 128 bits. :::tip use sipHash128Reference for new projects This 128-bit variant differs from the reference implementation and is weaker. This version exists because, when it was written, there was no official 128-bit extension for SipHash. New projects are advised to use sipHash128Reference . ::: Syntax sql sipHash128(arg1[, arg2, ...]) Arguments arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any Returned value Returns a 128-bit SipHash hash value. FixedString(16) Examples Usage example sql title=Query SELECT hex(sipHash128('foo', '\x01', 3)); response title=Response ┌─hex(sipHash128('foo', '', 3))────┐ │ 9DE516A64A414D4B1B609415E4523F24 │ └──────────────────────────────────┘ sipHash128Keyed {#sipHash128Keyed} Introduced in: v23.2 Same as sipHash128 but additionally takes an explicit key argument instead of using a fixed key. :::tip use sipHash128ReferenceKeyed for new projects This 128-bit variant differs from the reference implementation and it's weaker. This version exists because, when it was written, there was no official 128-bit extension for SipHash. New projects should probably use sipHash128ReferenceKeyed . ::: Syntax sql sipHash128Keyed((k0, k1), [arg1, arg2, ...]) Arguments (k0, k1) — A tuple of two UInt64 values representing the key. Tuple(UInt64, UInt64) arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any Returned value A 128-bit SipHash hash value of type FixedString(16) . FixedString(16) Examples Usage example sql title=Query SELECT hex(sipHash128Keyed((506097522914230528, 1084818905618843912),'foo', '\x01', 3));
{"source_file": "hash-functions.md"}
[ -0.016672007739543915, -0.04109321907162666, -0.030455458909273148, -0.036211345344781876, -0.09995459765195847, -0.01428973488509655, 0.055714480578899384, 0.034659840166568756, 0.01434634905308485, 0.004053947515785694, 0.005631391890347004, -0.0017066557193174958, 0.05262771248817444, -...
3df16b2a-3725-4929-b7be-4f2ff12b2109
Examples Usage example sql title=Query SELECT hex(sipHash128Keyed((506097522914230528, 1084818905618843912),'foo', '\x01', 3)); response title=Response ┌─hex(sipHash128Keyed((506097522914230528, 1084818905618843912), 'foo', '', 3))─┐ │ B8467F65C8B4CFD9A5F8BD733917D9BF │ └───────────────────────────────────────────────────────────────────────────────┘ sipHash128Reference {#sipHash128Reference} Introduced in: v23.2 Like sipHash128 but implements the 128-bit algorithm from the original authors of SipHash. Syntax sql sipHash128Reference(arg1[, arg2, ...]) Arguments arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any Returned value Returns the computed 128-bit SipHash hash value of the input arguments. FixedString(16) Examples Usage example sql title=Query SELECT hex(sipHash128Reference('foo', '', 3)); response title=Response ┌─hex(sipHash128Reference('foo', '', 3))─┐ │ 4D1BE1A22D7F5933C0873E1698426260 │ └────────────────────────────────────────┘ sipHash128ReferenceKeyed {#sipHash128ReferenceKeyed} Introduced in: v23.2 Same as sipHash128Reference but additionally takes an explicit key argument instead of using a fixed key. Syntax sql sipHash128ReferenceKeyed((k0, k1), arg1[, arg2, ...]) Arguments (k0, k1) — Tuple of two values representing the key Tuple(UInt64, UInt64) arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any Returned value Returns the computed 128-bit SipHash hash value of the input arguments. FixedString(16) Examples Usage example sql title=Query SELECT hex(sipHash128Reference('foo', '', 3)); response title=Response ┌─hex(sipHash128Reference('foo', '', 3))─┐ │ 4D1BE1A22D7F5933C0873E1698426260 │ └────────────────────────────────────────┘ sipHash64 {#sipHash64} Introduced in: v1.1 Produces a 64-bit SipHash hash value. This is a cryptographic hash function. It works at least three times faster than the MD5 hash function. The function interprets all the input parameters as strings and calculates the hash value for each of them. It then combines the hashes using the following algorithm: The first and the second hash value are concatenated to an array which is hashed. The previously calculated hash value and the hash of the third input parameter are hashed in a similar way. This calculation is repeated for all remaining hash values of the original input. :::note the calculated hash values may be equal for the same input values of different argument types. This affects for example integer types of different size, named and unnamed Tuple with the same data, Map and the corresponding Array(Tuple(key, value)) type with the same data. ::: Syntax sql sipHash64(arg1[, arg2, ...]) Arguments arg1[, arg2, ...] — A variable number of input arguments. Any Returned value
{"source_file": "hash-functions.md"}
[ 0.009566139429807663, -0.0031128190457820892, -0.03181884065270424, -0.053888678550720215, -0.10032843053340912, -0.03263801336288452, 0.09203485399484634, 0.0018382052658125758, 0.029721908271312714, 0.011326889507472515, -0.018232781440019608, 0.02904037944972515, 0.07161663472652435, -0...
d6cbb724-ce19-433a-b865-f5e726b1dbfc
Syntax sql sipHash64(arg1[, arg2, ...]) Arguments arg1[, arg2, ...] — A variable number of input arguments. Any Returned value Returns a computed hash value of the input arguments. UInt64 Examples Usage example sql title=Query SELECT sipHash64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS SipHash, toTypeName(SipHash) AS type; response title=Response ┌──────────────SipHash─┬─type───┐ │ 11400366955626497465 │ UInt64 │ └──────────────────────┴────────┘ sipHash64Keyed {#sipHash64Keyed} Introduced in: v23.2 Like sipHash64 but additionally takes an explicit key argument instead of using a fixed key. Syntax sql sipHash64Keyed((k0, k1), arg1[,arg2, ...]) Arguments (k0, k1) — A tuple of two values representing the key. Tuple(UInt64, UInt64) arg1[,arg2, ...] — A variable number of input arguments. Any Returned value Returns the computed hash of the input values. UInt64 Examples Usage example sql title=Query SELECT sipHash64Keyed((506097522914230528, 1084818905618843912), array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS SipHash, toTypeName(SipHash) AS type; response title=Response ┌─────────────SipHash─┬─type───┐ │ 8017656310194184311 │ UInt64 │ └─────────────────────┴────────┘ wordShingleMinHash {#wordShingleMinHash} Introduced in: v21.1 Splits a ASCII string into parts (shingles) of shinglesize words, calculates hash values for each word shingle and returns a tuple with these hashes. Uses hashnum minimum hashes to calculate the minimum hash and hashnum maximum hashes to calculate the maximum hash. It is case sensitive. Can be used to detect semi-duplicate strings with tupleHammingDistance . For two strings, if the returned hashes are the same for both strings, then those strings are the same. Syntax sql wordShingleMinHash(string[, shinglesize, hashnum]) Arguments string — String for which to compute the hash. String shinglesize — Optional. The size of a word shingle, any number from 1 to 25 . The default value is 3 . UInt8 hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25 . The default value is 6 . UInt8 Returned value Returns a tuple with two hashes — the minimum and the maximum. Tuple(UInt64, UInt64) Examples Usage example sql title=Query SELECT wordShingleMinHash('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Tuple; response title=Response ┌─Tuple──────────────────────────────────────┐ │ (16452112859864147620,5844417301642981317) │ └────────────────────────────────────────────┘ wordShingleMinHashArg {#wordShingleMinHashArg} Introduced in: v1.1
{"source_file": "hash-functions.md"}
[ 0.03891481086611748, -0.018051207065582275, -0.03691118583083153, -0.03167075291275978, -0.1020379513502121, -0.03151284530758858, 0.11365135759115219, -0.006036569830030203, 0.006351145450025797, 0.02314138412475586, 0.008905190043151379, 0.020011095330119133, 0.045113109052181244, -0.037...
8bc9f56c-0d9c-4efa-bc78-f350e5dae4a3
wordShingleMinHashArg {#wordShingleMinHashArg} Introduced in: v1.1 Splits a ASCII string into parts (shingles) of shinglesize words each and returns the shingles with minimum and maximum word hashes, calculated by the wordShingleMinHash function with the same input. It is case sensitive. Syntax sql wordShingleMinHashArg(string[, shinglesize, hashnum]) Arguments string — String for which to compute the hash. String shinglesize — Optional. The size of a word shingle, any number from 1 to 25 . The default value is 3 . UInt8 hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25 . The default value is 6 . UInt8 Returned value Returns a tuple with two tuples with hashnum word shingles each. Tuple(Tuple(String)) Examples Usage example sql title=Query SELECT wordShingleMinHashArg('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).', 1, 3) AS Tuple; response title=Response ┌─Tuple─────────────────────────────────────────────────────────────────┐ │ (('OLAP','database','analytical'),('online','oriented','processing')) │ └───────────────────────────────────────────────────────────────────────┘ wordShingleMinHashArgCaseInsensitive {#wordShingleMinHashArgCaseInsensitive} Introduced in: v21.1 Splits a ASCII string into parts (shingles) of shinglesize words each and returns the shingles with minimum and maximum word hashes, calculated by the wordShingleMinHashCaseInsensitive function with the same input. It is case insensitive. Syntax sql wordShingleMinHashArgCaseInsensitive(string[, shinglesize, hashnum]) Arguments string — String for which to compute the hash. String shinglesize — Optional. The size of a word shingle, any number from 1 to 25 . The default value is 3 . UInt8 hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25 . The default value is 6 . UInt8 Returned value Returns a tuple with two tuples with hashnum word shingles each. Tuple(Tuple(String)) Examples Usage example sql title=Query SELECT wordShingleMinHashArgCaseInsensitive('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).', 1, 3) AS Tuple; response title=Response ┌─Tuple──────────────────────────────────────────────────────────────────┐ │ (('queries','database','analytical'),('oriented','processing','DBMS')) │ └────────────────────────────────────────────────────────────────────────┘ wordShingleMinHashArgCaseInsensitiveUTF8 {#wordShingleMinHashArgCaseInsensitiveUTF8} Introduced in: v21.1
{"source_file": "hash-functions.md"}
[ -0.004290532320737839, 0.04859232157468796, -0.038667771965265274, -0.0348723903298378, -0.1160888671875, -0.04461364820599556, 0.11491762846708298, 0.055799584835767746, -0.028439361602067947, 0.00311727961525321, 0.013196941465139389, -0.01526370644569397, 0.12129293382167816, -0.0430540...
aee76ec9-3bb4-4348-b498-217a56a2bfca
wordShingleMinHashArgCaseInsensitiveUTF8 {#wordShingleMinHashArgCaseInsensitiveUTF8} Introduced in: v21.1 Splits a UTF-8 string into parts (shingles) of shinglesize words each and returns the shingles with minimum and maximum word hashes, calculated by the wordShingleMinHashCaseInsensitiveUTF8 function with the same input. It is case insensitive. Syntax sql wordShingleMinHashArgCaseInsensitiveUTF8(string[, shinglesize, hashnum]) Arguments string — String for which to compute the hash. String shinglesize — Optional. The size of a word shingle, any number from 1 to 25 . The default value is 3 . UInt8 hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25 . The default value is 6 . UInt8 Returned value Returns a tuple with two tuples with hashnum word shingles each. Tuple(Tuple(String)) Examples Usage example sql title=Query SELECT wordShingleMinHashArgCaseInsensitiveUTF8('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).', 1, 3) AS Tuple; response title=Response ┌─Tuple──────────────────────────────────────────────────────────────────┐ │ (('queries','database','analytical'),('oriented','processing','DBMS')) │ └────────────────────────────────────────────────────────────────────────┘ wordShingleMinHashArgUTF8 {#wordShingleMinHashArgUTF8} Introduced in: v21.1 Splits a UTF-8 string into parts (shingles) of shinglesize words each and returns the shingles with minimum and maximum word hashes, calculated by the wordShingleMinHashUTF8 function with the same input. It is case sensitive. Syntax sql wordShingleMinHashArgUTF8(string[, shinglesize, hashnum]) Arguments string — String for which to compute the hash. String shinglesize — Optional. The size of a word shingle, any number from 1 to 25 . The default value is 3 . UInt8 hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25 . The default value is 6 . UInt8 Returned value Returns a tuple with two tuples with hashnum word shingles each. Tuple(Tuple(String)) Examples Usage example sql title=Query SELECT wordShingleMinHashArgUTF8('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).', 1, 3) AS Tuple; response title=Response ┌─Tuple─────────────────────────────────────────────────────────────────┐ │ (('OLAP','database','analytical'),('online','oriented','processing')) │ └───────────────────────────────────────────────────────────────────────┘ wordShingleMinHashCaseInsensitive {#wordShingleMinHashCaseInsensitive} Introduced in: v21.1
{"source_file": "hash-functions.md"}
[ 0.01483040302991867, 0.032852642238140106, 0.002201175084337592, -0.03679518774151802, -0.0904727578163147, -0.008245722390711308, 0.11955822259187698, 0.08186623454093933, -0.04802863672375679, -0.0025556725449860096, -0.013149434700608253, -0.019757699221372604, 0.13161160051822662, -0.0...
6acca64c-915b-451b-b797-07e204a7255d
wordShingleMinHashCaseInsensitive {#wordShingleMinHashCaseInsensitive} Introduced in: v21.1 Splits a ASCII string into parts (shingles) of shinglesize words, calculates hash values for each word shingle and returns a tuple with these hashes. Uses hashnum minimum hashes to calculate the minimum hash and hashnum maximum hashes to calculate the maximum hash. It is case insensitive. Can be used to detect semi-duplicate strings with tupleHammingDistance . For two strings, if the returned hashes are the same for both strings, then those strings are the same. Syntax sql wordShingleMinHashCaseInsensitive(string[, shinglesize, hashnum]) Arguments string — String for which to compute the hash. String shinglesize — Optional. The size of a word shingle, any number from 1 to 25 . The default value is 3 . UInt8 hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25 . The default value is 6 . UInt8 Returned value Returns a tuple with two hashes — the minimum and the maximum. Tuple(UInt64, UInt64) Examples Usage example sql title=Query SELECT wordShingleMinHashCaseInsensitive('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Tuple; response title=Response ┌─Tuple─────────────────────────────────────┐ │ (3065874883688416519,1634050779997673240) │ └───────────────────────────────────────────┘ wordShingleMinHashCaseInsensitiveUTF8 {#wordShingleMinHashCaseInsensitiveUTF8} Introduced in: v21.1 Splits a UTF-8 string into parts (shingles) of shinglesize words, calculates hash values for each word shingle and returns a tuple with these hashes. Uses hashnum minimum hashes to calculate the minimum hash and hashnum maximum hashes to calculate the maximum hash. It is case insensitive. Can be used to detect semi-duplicate strings with tupleHammingDistance . For two strings, if the returned hashes are the same for both strings, then those strings are the same. Syntax sql wordShingleMinHashCaseInsensitiveUTF8(string[, shinglesize, hashnum]) Arguments string — String for which to compute the hash. String shinglesize — Optional. The size of a word shingle, any number from 1 to 25 . The default value is 3 . UInt8 hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25 . The default value is 6 . UInt8 Returned value Returns a tuple with two hashes — the minimum and the maximum. Tuple(UInt64, UInt64) Examples Usage example sql title=Query SELECT wordShingleMinHashCaseInsensitiveUTF8('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Tuple; response title=Response ┌─Tuple─────────────────────────────────────┐ │ (3065874883688416519,1634050779997673240) │ └───────────────────────────────────────────┘
{"source_file": "hash-functions.md"}
[ -0.003349351231008768, -0.02679954655468464, -0.02251797914505005, -0.05190994590520859, -0.10909920185804367, -0.021520735695958138, 0.1246972382068634, 0.03474389761686325, -0.06038763001561165, -0.03431689739227295, 0.0029827465768903494, 0.006614896468818188, 0.12413600087165833, -0.02...
0a9803d1-ee75-4ff9-a781-4c356d2ad425
response title=Response ┌─Tuple─────────────────────────────────────┐ │ (3065874883688416519,1634050779997673240) │ └───────────────────────────────────────────┘ wordShingleMinHashUTF8 {#wordShingleMinHashUTF8} Introduced in: v21.1 Splits a UTF-8 string into parts (shingles) of shinglesize words, calculates hash values for each word shingle and returns a tuple with these hashes. Uses hashnum minimum hashes to calculate the minimum hash and hashnum maximum hashes to calculate the maximum hash. It is case sensitive. Can be used to detect semi-duplicate strings with tupleHammingDistance . For two strings, if the returned hashes are the same for both strings, then those strings are the same. Syntax sql wordShingleMinHashUTF8(string[, shinglesize, hashnum]) Arguments string — String for which to compute the hash. String shinglesize — Optional. The size of a word shingle, any number from 1 to 25 . The default value is 3 . UInt8 hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25 . The default value is 6 . UInt8 Returned value Returns a tuple with two hashes — the minimum and the maximum. Tuple(UInt64, UInt64) Examples Usage example sql title=Query SELECT wordShingleMinHashUTF8('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Tuple; response title=Response ┌─Tuple──────────────────────────────────────┐ │ (16452112859864147620,5844417301642981317) │ └────────────────────────────────────────────┘ wordShingleSimHash {#wordShingleSimHash} Introduced in: v21.1 Splits a ASCII string into parts (shingles) of shinglesize words and returns the word shingle simhash . Is is case sensitive. Can be used for detection of semi-duplicate strings with bitHammingDistance . The smaller the Hamming distance of the calculated simhashes of two strings, the more likely these strings are the same. Syntax sql wordShingleSimHash(string[, shinglesize]) Arguments string — String for which to compute the hash. String shinglesize — Optional. The size of a word shingle, any number from 1 to 25 . The default value is 3 . UInt8 Returned value Returns the computed hash value. UInt64 Examples Usage example sql title=Query SELECT wordShingleSimHash('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Hash; response title=Response ┌───────Hash─┐ │ 2328277067 │ └────────────┘ wordShingleSimHashCaseInsensitive {#wordShingleSimHashCaseInsensitive} Introduced in: v21.1 Splits a ASCII string into parts (shingles) of shinglesize words and returns the word shingle simhash . It is case insensitive.
{"source_file": "hash-functions.md"}
[ -0.01954302377998829, -0.017190800979733467, -0.02376711368560791, -0.034737180918455124, -0.1206064447760582, -0.03240601345896721, 0.10777198523283005, -0.007426528725773096, -0.031976230442523956, -0.03668065369129181, -0.009059401229023933, 0.00037135582533665, 0.1501796841621399, -0.0...
29acdd86-6e19-4c54-ac25-f882af064659
Introduced in: v21.1 Splits a ASCII string into parts (shingles) of shinglesize words and returns the word shingle simhash . It is case insensitive. Can be used for detection of semi-duplicate strings with bitHammingDistance . The smaller the Hamming distance of the calculated simhashes of two strings, the more likely these strings are the same. Syntax sql wordShingleSimHashCaseInsensitive(string[, shinglesize]) Arguments string — String for which to compute the hash. String shinglesize — Optional. The size of a word shingle, any number from 1 to 25 . The default value is 3 . UInt8 Returned value Returns the computed hash value. UInt64 Examples Usage example sql title=Query SELECT wordShingleSimHashCaseInsensitive('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Hash; response title=Response ┌───────Hash─┐ │ 2194812424 │ └────────────┘ wordShingleSimHashCaseInsensitiveUTF8 {#wordShingleSimHashCaseInsensitiveUTF8} Introduced in: v1.1 Splits a UTF-8 encoded string into parts (shingles) of shinglesize words and returns the word shingle simhash . It is case insensitive. Can be used for detection of semi-duplicate strings with bitHammingDistance . The smaller the Hamming Distance of the calculated simhashes of two strings, the more likely these strings are the same. Syntax sql wordShingleSimHashCaseInsensitiveUTF8(string[, shinglesize]) Arguments string — String for which to compute the hash. String shinglesize — Optional. The size of a word shingle, any number from 1 to 25 . The default value is 3 . UInt8 Returned value Returns the computed hash value. UInt64 Examples Usage example sql title=Query SELECT wordShingleSimHashCaseInsensitiveUTF8('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Hash; response title=Response ┌───────Hash─┐ │ 2194812424 │ └────────────┘ wordShingleSimHashUTF8 {#wordShingleSimHashUTF8} Introduced in: v21.1 Splits a UTF-8 string into parts (shingles) of shinglesize words and returns the word shingle simhash . It is case sensitive. Can be used for detection of semi-duplicate strings with bitHammingDistance . The smaller the Hamming distance of the calculated simhashes of two strings, the more likely these strings are the same. Syntax sql wordShingleSimHashUTF8(string[, shinglesize]) Arguments string — String for which to compute the hash. String shinglesize — Optional. The size of a word shingle, any number from 1 to 25 . The default value is 3 . UInt8 Returned value Returns the computed hash value. UInt64 Examples Usage example sql title=Query SELECT wordShingleSimHashUTF8('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Hash;
{"source_file": "hash-functions.md"}
[ -0.02452579326927662, 0.03652438521385193, -0.06413816660642624, -0.03425575792789459, -0.10197033733129501, -0.06169559434056282, 0.07476983964443207, 0.06411954760551453, -0.01422417163848877, -0.03781265392899513, 0.013261848129332066, 0.025956206023693085, 0.11231213063001633, -0.05356...
aee3b29d-dfc0-4966-b1f3-332b3003b933
Usage example sql title=Query SELECT wordShingleSimHashUTF8('ClickHouse® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Hash; response title=Response ┌───────Hash─┐ │ 2328277067 │ └────────────┘ wyHash64 {#wyHash64} Introduced in: v22.7 Computes a 64-bit wyHash64 hash value. Syntax sql wyHash64(arg) Arguments arg — String argument for which to compute the hash. String Returned value Returns the computed 64-bit hash value UInt64 Examples Usage example sql title=Query SELECT wyHash64('ClickHouse') AS Hash; response title=Response 12336419557878201794 xxHash32 {#xxHash32} Introduced in: v20.1 Calculates a xxHash from a string. For the 64-bit version see xxHash64 Syntax sql xxHash32(arg) Arguments arg — Input string to hash. String Returned value Returns the computed 32-bit hash of the input string. UInt32 Examples Usage example sql title=Query SELECT xxHash32('Hello, world!'); response title=Response ┌─xxHash32('Hello, world!')─┐ │ 834093149 │ └───────────────────────────┘ xxHash64 {#xxHash64} Introduced in: v20.1 Calculates a xxHash from a string. For the 32-bit version see xxHash32 Syntax sql xxHash64(arg) Arguments arg — Input string to hash. String Returned value Returns the computed 64-bit hash of the input string. UInt64 Examples Usage example sql title=Query SELECT xxHash64('Hello, world!'); response title=Response ┌─xxHash64('Hello, world!')─┐ │ 17691043854468224118 │ └───────────────────────────┘ xxh3 {#xxh3} Introduced in: v22.12 Computes a XXH3 64-bit hash value. Syntax sql xxh3(expr) Arguments expr — A list of expressions of any data type. Any Returned value Returns the computed 64-bit xxh3 hash value UInt64 Examples Usage example sql title=Query SELECT xxh3('ClickHouse') response title=Response 18009318874338624809
{"source_file": "hash-functions.md"}
[ 0.05007975175976753, 0.02442200854420662, -0.07448218762874603, 0.022154834121465683, -0.08575595915317535, -0.07659177482128143, 0.0495171993970871, -0.012249927967786789, 0.009624224156141281, 0.06340554356575012, -0.009687994606792927, 0.0136111443862319, 0.06474193185567856, -0.0934641...
594350f5-8dbc-44a7-a857-960c75e37425
description: 'Documentation for Functions for Working with UUIDs' sidebar_label: 'UUIDs' slug: /sql-reference/functions/uuid-functions title: 'Functions for Working with UUIDs' doc_type: 'reference' import DeprecatedBadge from '@theme/badges/DeprecatedBadge'; Functions for working with UUIDs UUIDv7 generation {#uuidv7-generation} The generated UUID contains a 48-bit timestamp in Unix milliseconds, followed by version "7" (4 bits), a counter (42 bits) to distinguish UUIDs within a millisecond (including a variant field "2", 2 bits), and a random field (32 bits). For any given timestamp ( unix_ts_ms ), the counter starts at a random value and is incremented by 1 for each new UUID until the timestamp changes. In case the counter overflows, the timestamp field is incremented by 1 and the counter is reset to a random new start value. The UUID generation functions guarantee that the counter field within a timestamp increments monotonically across all function invocations in concurrently running threads and queries. text 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 ├─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤ | unix_ts_ms | ├─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤ | unix_ts_ms | ver | counter_high_bits | ├─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤ |var| counter_low_bits | ├─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤ | rand_b | └─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘ Snowflake ID generation {#snowflake-id-generation} The generated Snowflake ID contains the current Unix timestamp in milliseconds (41 + 1 top zero bits), followed by a machine id (10 bits), and a counter (12 bits) to distinguish IDs within a millisecond. For any given timestamp ( unix_ts_ms ), the counter starts at 0 and is incremented by 1 for each new Snowflake ID until the timestamp changes. In case the counter overflows, the timestamp field is incremented by 1 and the counter is reset to 0. :::note The generated Snowflake IDs are based on the UNIX epoch 1970-01-01. While no standard or recommendation exists for the epoch of Snowflake IDs, implementations in other systems may use a different epoch, e.g. Twitter/X (2010-11-04) or Mastodon (2015-01-01). :::
{"source_file": "uuid-functions.md"}
[ -0.1027374193072319, 0.018760882318019867, -0.04440395534038544, 0.020030390471220016, 0.021216537803411484, -0.025373630225658417, 0.04250770062208176, -0.0177574772387743, 0.007759098429232836, -0.031745247542858124, -0.003324621357023716, -0.007801437750458717, 0.058452725410461426, -0....
b79afba1-15fc-4bda-b99e-c1fc2b2a8e56
text 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 ├─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤ |0| timestamp | ├─┼ ┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼─┤ | | machine_id | machine_seq_num | └─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┘ generateUUIDv4 {#generateuuidv4} Generates a version 4 UUID . Syntax sql generateUUIDv4([expr]) Arguments expr — An arbitrary expression used to bypass common subexpression elimination if the function is called multiple times in a query. The value of the expression has no effect on the returned UUID. Optional. Returned value A value of type UUIDv4. Example First, create a table with a column of type UUID, then insert a generated UUIDv4 into the table. ```sql CREATE TABLE tab (uuid UUID) ENGINE = Memory; INSERT INTO tab SELECT generateUUIDv4(); SELECT * FROM tab; ``` Result: response ┌─────────────────────────────────uuid─┐ │ f4bf890f-f9dc-4332-ad5c-0c18e73f28e9 │ └──────────────────────────────────────┘ Example with multiple UUIDs generated per row ```sql SELECT generateUUIDv4(1), generateUUIDv4(2); ┌─generateUUIDv4(1)────────────────────┬─generateUUIDv4(2)────────────────────┐ │ 2d49dc6e-ddce-4cd0-afb8-790956df54c1 │ 8abf8c13-7dea-4fdf-af3e-0e18767770e6 │ └──────────────────────────────────────┴──────────────────────────────────────┘ ``` generateUUIDv7 {#generateUUIDv7} Generates a version 7 UUID . See section "UUIDv7 generation" for details on UUID structure, counter management, and concurrency guarantees. :::note As of April 2024, version 7 UUIDs are in draft status and their layout may change in future. ::: Syntax sql generateUUIDv7([expr]) Arguments expr — An arbitrary expression used to bypass common subexpression elimination if the function is called multiple times in a query. The value of the expression has no effect on the returned UUID. Optional. Returned value A value of type UUIDv7. Example First, create a table with a column of type UUID, then insert a generated UUIDv7 into the table. ```sql CREATE TABLE tab (uuid UUID) ENGINE = Memory; INSERT INTO tab SELECT generateUUIDv7(); SELECT * FROM tab; ``` Result: response ┌─────────────────────────────────uuid─┐ │ 018f05af-f4a8-778f-beee-1bedbc95c93b │ └──────────────────────────────────────┘ Example with multiple UUIDs generated per row ```sql SELECT generateUUIDv7(1), generateUUIDv7(2); ┌─generateUUIDv7(1)────────────────────┬─generateUUIDv7(2)────────────────────┐ │ 018f05c9-4ab8-7b86-b64e-c9f03fbd45d1 │ 018f05c9-4ab8-7b86-b64e-c9f12efb7e16 │ └──────────────────────────────────────┴──────────────────────────────────────┘ ``` dateTimeToUUIDv7 {#datetimetouuidv7} Converts a DateTime value to a UUIDv7 at the given time.
{"source_file": "uuid-functions.md"}
[ -0.03422149270772934, 0.08540818095207214, -0.03760753571987152, 0.038628946989774704, -0.0009136997978202999, -0.03894945606589317, 0.0487055703997612, -0.010041219182312489, -0.01154414750635624, -0.03784802183508873, 0.025362243875861168, -0.09863590449094772, 0.0703422874212265, -0.080...
6bc75d21-94a9-4cb9-b37b-d92080e67f57
dateTimeToUUIDv7 {#datetimetouuidv7} Converts a DateTime value to a UUIDv7 at the given time. See section "UUIDv7 generation" for details on UUID structure, counter management, and concurrency guarantees. :::note As of April 2024, version 7 UUIDs are in draft status and their layout may change in future. ::: Syntax sql dateTimeToUUIDv7(value) Arguments value — Date with time. DateTime . Returned value A value of type UUIDv7. Example sql SELECT dateTimeToUUIDv7(toDateTime('2021-08-15 18:57:56', 'Asia/Shanghai')); Result: response ┌─dateTimeToUUIDv7(toDateTime('2021-08-15 18:57:56', 'Asia/Shanghai'))─┐ │ 018f05af-f4a8-778f-beee-1bedbc95c93b │ └─────────────────────────────────────────────────────────────────────────┘ Example with multiple UUIDs for the same timestamp sql SELECT dateTimeToUUIDv7(toDateTime('2021-08-15 18:57:56')); SELECT dateTimeToUUIDv7(toDateTime('2021-08-15 18:57:56')); Result ```response ┌─dateTimeToUUIDv7(t⋯08-15 18:57:56'))─┐ 1. │ 017b4b2d-7720-76ed-ae44-bbcc23a8c550 │ └──────────────────────────────────────┘ ┌─dateTimeToUUIDv7(t⋯08-15 18:57:56'))─┐ 1. │ 017b4b2d-7720-76ed-ae44-bbcf71ed0fd3 │ └──────────────────────────────────────┘ ``` The function ensures that multiple calls with the same timestamp generate unique, monotonically increasing UUIDs. empty {#empty} Checks whether the input UUID is empty. Syntax sql empty(UUID) The UUID is considered empty if it contains all zeros (zero UUID). The function also works for Arrays and Strings. Arguments x — A UUID. UUID . Returned value Returns 1 for an empty UUID or 0 for a non-empty UUID. UInt8 . Example To generate the UUID value, ClickHouse provides the generateUUIDv4 function. Query: sql SELECT empty(generateUUIDv4()); Result: response ┌─empty(generateUUIDv4())─┐ │ 0 │ └─────────────────────────┘ notEmpty {#notempty} Checks whether the input UUID is non-empty. Syntax sql notEmpty(UUID) The UUID is considered empty if it contains all zeros (zero UUID). The function also works for Arrays and Strings. Arguments x — A UUID. UUID . Returned value Returns 1 for a non-empty UUID or 0 for an empty UUID. UInt8 . Example To generate the UUID value, ClickHouse provides the generateUUIDv4 function. Query: sql SELECT notEmpty(generateUUIDv4()); Result: response ┌─notEmpty(generateUUIDv4())─┐ │ 1 │ └────────────────────────────┘ toUUID {#touuid} Converts a value of type String to a UUID. sql toUUID(string) Returned value The UUID type value. Usage example sql SELECT toUUID('61f0c404-5cb3-11e7-907b-a6006ad3dba0') AS uuid Result: response ┌─────────────────────────────────uuid─┐ │ 61f0c404-5cb3-11e7-907b-a6006ad3dba0 │ └──────────────────────────────────────┘ toUUIDOrDefault {#touuidordefault} Arguments
{"source_file": "uuid-functions.md"}
[ -0.042376674711704254, 0.009380094707012177, -0.008053699508309364, 0.05824838951230049, 0.0036892665084451437, -0.037743862718343735, 0.07423710078001022, -0.04940284788608551, 0.02306791953742504, -0.0019611285533756018, 0.014912388287484646, -0.1379372477531433, 0.01824674755334854, 0.0...
0d1234f6-118d-48b7-bd4c-4d0c6d6c0b60
Result: response ┌─────────────────────────────────uuid─┐ │ 61f0c404-5cb3-11e7-907b-a6006ad3dba0 │ └──────────────────────────────────────┘ toUUIDOrDefault {#touuidordefault} Arguments string — String of 36 characters or FixedString(36). String . default — UUID to be used as the default if the first argument cannot be converted to a UUID type. UUID . Returned value UUID sql toUUIDOrDefault(string, default) Returned value The UUID type value. Usage examples This first example returns the first argument converted to a UUID type as it can be converted: sql SELECT toUUIDOrDefault('61f0c404-5cb3-11e7-907b-a6006ad3dba0', cast('59f0c404-5cb3-11e7-907b-a6006ad3dba0' AS UUID)); Result: response ┌─toUUIDOrDefault('61f0c404-5cb3-11e7-907b-a6006ad3dba0', CAST('59f0c404-5cb3-11e7-907b-a6006ad3dba0', 'UUID'))─┐ │ 61f0c404-5cb3-11e7-907b-a6006ad3dba0 │ └───────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ This second example returns the second argument (the provided default UUID) as the first argument cannot be converted to a UUID type: sql SELECT toUUIDOrDefault('-----61f0c404-5cb3-11e7-907b-a6006ad3dba0', cast('59f0c404-5cb3-11e7-907b-a6006ad3dba0' AS UUID)); Result: response ┌─toUUIDOrDefault('-----61f0c404-5cb3-11e7-907b-a6006ad3dba0', CAST('59f0c404-5cb3-11e7-907b-a6006ad3dba0', 'UUID'))─┐ │ 59f0c404-5cb3-11e7-907b-a6006ad3dba0 │ └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ toUUIDOrNull {#touuidornull} Takes an argument of type String and tries to parse it into UUID. If failed, returns NULL. sql toUUIDOrNull(string) Returned value The Nullable(UUID) type value. Usage example sql SELECT toUUIDOrNull('61f0c404-5cb3-11e7-907b-a6006ad3dba0T') AS uuid Result: response ┌─uuid─┐ │ ᴺᵁᴸᴸ │ └──────┘ toUUIDOrZero {#touuidorzero} It takes an argument of type String and tries to parse it into UUID. If failed, returns zero UUID. sql toUUIDOrZero(string) Returned value The UUID type value. Usage example sql SELECT toUUIDOrZero('61f0c404-5cb3-11e7-907b-a6006ad3dba0T') AS uuid Result: response ┌─────────────────────────────────uuid─┐ │ 00000000-0000-0000-0000-000000000000 │ └──────────────────────────────────────┘ UUIDStringToNum {#uuidstringtonum} Accepts string containing 36 characters in the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx , and returns a FixedString(16) as its binary representation, with its format optionally specified by variant ( Big-endian by default). Syntax sql UUIDStringToNum(string[, variant = 1]) Arguments string — A String of 36 characters or FixedString
{"source_file": "uuid-functions.md"}
[ 0.02236994355916977, -0.006586412433534861, -0.049218155443668365, 0.01719578541815281, -0.03931761160492897, -0.01951446197926998, 0.11586321890354156, 0.02023954875767231, -0.03644226863980293, -0.0336356945335865, -0.010156191885471344, -0.07312517613172531, -0.008328108116984367, -0.00...
21b54822-1a11-46bd-bdc4-429f548c3db5
Syntax sql UUIDStringToNum(string[, variant = 1]) Arguments string — A String of 36 characters or FixedString variant — Integer, representing a variant as specified by RFC4122 . 1 = Big-endian (default), 2 = Microsoft . Returned value FixedString(16) Usage examples sql SELECT '612f3c40-5d3b-217e-707b-6a546a3d7b29' AS uuid, UUIDStringToNum(uuid) AS bytes Result: response ┌─uuid─────────────────────────────────┬─bytes────────────┐ │ 612f3c40-5d3b-217e-707b-6a546a3d7b29 │ a/<@];!~p{jTj={) │ └──────────────────────────────────────┴──────────────────┘ sql SELECT '612f3c40-5d3b-217e-707b-6a546a3d7b29' AS uuid, UUIDStringToNum(uuid, 2) AS bytes Result: ```response ┌─uuid─────────────────────────────────┬─bytes────────────┐ │ 612f3c40-5d3b-217e-707b-6a546a3d7b29 │ @
{"source_file": "uuid-functions.md"}
[ -0.02117176353931427, -0.002677198499441147, -0.024039017036557198, -0.00789781752973795, -0.02584991604089737, -0.05173762887716293, 0.10111157596111298, 0.05557376146316528, -0.033135946840047836, 0.0021349508315324783, -0.047267768532037735, -0.01996193826198578, 0.03436993807554245, -0...
17a39e4d-a1ff-4ee9-a08d-0dc924611a42
description: 'Documentation for Functions for Working with Time Series' sidebar_label: 'TimeSeries' slug: /sql-reference/functions/time-series-functions title: 'Functions for Working with Time Series' doc_type: 'reference' Time series functions Below functions are designed to be used with timeSeries*() aggregate functions like timeSeriesInstantRateToGrid , timeSeriesLastToGrid , and so on. timeSeriesRange {#timeSeriesRange} Generates a range of timestamps. Syntax sql timeSeriesRange(start_timestamp, end_timestamp, step) Arguments start_timestamp - Start of the range. end_timestamp - End of the range. step - Step of the range in seconds. Returned value Returns a range of timestamps [start_timestamp, start_timestamp + step, start_timestamp + 2 * step, ..., end_timestamp] . Examples Query: sql SELECT timeSeriesRange('2025-06-01 00:00:00'::DateTime64(3), '2025-06-01 00:01:00'::DateTime64(3), 30) AS rng; Result: text ┌────────────────────────────────────result─────────────────────────────────────────┐ │ ['2025-06-01 00:00:00.000', '2025-06-01 00:00:30.000', '2025-06-01 00:01:00.000'] │ └───────────────────────────────────────────────────────────────────────────────────┘ Notes - If function timeSeriesRange() is called with start_timestamp equal to end_timestamp then it returns a 1-element array containing that timestamp: [start_timestamp] - Function timeSeriesRange() is similar to function range . For example, if the type of timestamps is DateTime64(3) and start_timestamp < end_timestamp then timeSeriesRange(start_timestamp, end_timestamp, step) returns the same result as the following expression: sql range(start_timestamp::Int64, end_timestamp::Int64 + 1, step::Int64)::Array(DateTime64(3)) timeSeriesFromGrid {#timeSeriesFromGrid} Converts array of values [value1, value2, value3, ..., valueN] to array of tuples [(start_timestamp, value1), (start_timestamp + step, value2), (start_timestamp + 2 * step, value3), ..., (end_timestamp, valueN)] . If some of the values [value1, value2, value3, ...] are NULL then the function won't copy such null values to the result array but will still increase the current timestamp, i.e. for example for [value1, NULL, value2] the function will return [(start_timestamp, value1), (start_timestamp + 2 * step, value2)] . The current timestamp is increased by step until it becomes greater than end_timestamp, each timestamp will be combined with a value from a specified array of values. If number of the values doesn't match number of the timestamps the function will throw an exception. Syntax sql timeSeriesFromGrid(start_timestamp, end_timestamp, step, values); Arguments start_timestamp - Start of the grid. end_timestamp - End of the grid. step - Step of the grid in seconds. values - Array of values [value1, value2, ..., valueN] . Returned value
{"source_file": "time-series-functions.md"}
[ -0.08592388033866882, -0.012507853098213673, 0.007613242603838444, 0.011811090633273125, -0.04469453915953636, 0.048928070813417435, -0.032159287482500076, 0.07997283339500427, 0.005369517952203751, -0.04891172796487808, -0.011374489404261112, -0.08931556344032288, -0.030377201735973358, -...
927bd826-89cf-44c8-ab0f-d80943c8ec45
start_timestamp - Start of the grid. end_timestamp - End of the grid. step - Step of the grid in seconds. values - Array of values [value1, value2, ..., valueN] . Returned value Returns values from the source array of values combined with timestamps on a regular time grid described by start_timestamp and step . Examples Query: sql SELECT timeSeriesFromGrid('2025-06-01 00:00:00'::DateTime64(3), '2025-06-01 00:01:30.000'::DateTime64(3), 30, [10, 20, NULL, 30]) AS result; Result: text ┌─────────────────────────────────────────────result─────────────────────────────────────────────┐ │ [('2025-06-01 00:00:00.000',10),('2025-06-01 00:00:30.000',20),('2025-06-01 00:01:30.000',30)] │ └────────────────────────────────────────────────────────────────────────────────────────────────┘ Note Function timeSeriesFromGrid(start_timestamp, end_timestamp, step, values) returns the same result as the following expression: sql arrayFilter(x -> x.2 IS NOT NULL, arrayZip(timeSeriesRange(start_timestamp, end_timestamp, step), values)) seriesDecomposeSTL {#seriesDecomposeSTL} Introduced in: v24.1 Decomposes a series data using STL (Seasonal-Trend Decomposition Procedure Based on Loess) into a season, a trend and a residual component. Syntax sql seriesDecomposeSTL(series, period) Arguments series — An array of numeric values Array((U)Int8/16/32/64) or Array(Float*) period — A positive integer UInt8/16/32/64 Returned value Returns an array of four arrays where the first array includes seasonal components, the second array - trend, the third array - residue component, and the fourth array - baseline(seasonal + trend) component. Array(Array(Float32), Array(Float32), Array(Float32), Array(Float32)) Examples Decompose series data using STL sql title=Query SELECT seriesDecomposeSTL([10.1, 20.45, 40.34, 10.1, 20.45, 40.34, 10.1, 20.45, 40.34, 10.1, 20.45, 40.34, 10.1, 20.45, 40.34, 10.1, 20.45, 40.34, 10.1, 20.45, 40.34, 10.1, 20.45, 40.34], 3) AS print_0
{"source_file": "time-series-functions.md"}
[ -0.06109295040369034, 0.044756632298231125, -0.04015164077281952, 0.03692380711436272, 0.0340832956135273, 0.014928540214896202, -0.038283005356788635, 0.04158962517976761, 0.051283374428749084, -0.03565055876970291, -0.020237989723682404, -0.06442730128765106, -0.08788245916366577, -0.018...
5d9d2557-24dc-4ea5-8c42-3a266689e9f5
response title=Response ┌───────────print_0──────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ [[ -13.529999, -3.1799996, 16.71, -13.53, -3.1799996, 16.71, -13.53, -3.1799996, 16.71, -13.530001, -3.18, 16.710001, -13.530001, -3.1800003, 16.710001, -13.530001, -3.1800003, 16.710001, -13.530001, -3.1799994, 16.71, -13.529999, -3.1799994, 16.709997 ], [ 23.63, 23.63, 23.630003, 23.630001, 23.630001, 23.630001, 23.630001, 23.630001, 23.630001, 23.630001, 23.630001, 23.63, 23.630001, 23.630001, 23.63, 23.630001, 23.630001, 23.63, 23.630001, 23.630001, 23.630001, 23.630001, 23.630001, 23.630003 ], [ 0, 0.0000019073486, -0.0000019073486, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.0000019073486, 0, 0 ], [ 10.1, 20.449999, 40.340004, 10.100001, 20.45, 40.34, 10.100001, 20.45, 40.34, 10.1, 20.45, 40.34, 10.1, 20.45, 40.34, 10.1, 20.45, 40.34, 10.1, 20.45, 40.34, 10.100002, 20.45, 40.34 ]] │ └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ seriesOutliersDetectTukey {#seriesOutliersDetectTukey} Introduced in: v24.2 Detects outliers in series data using Tukey Fences . Syntax sql seriesOutliersDetectTukey(series[, min_percentile, max_percentile, K]) Arguments series — An array of numeric values. Array((UInt8/16/32/64)) or Array(Float*) min_percentile — Optional. The minimum percentile to be used to calculate inter-quantile range (IQR) . The value must be in range [0.02,0.98]. The default is 0.25. Float* max_percentile — Optional. The maximum percentile to be used to calculate inter-quantile range (IQR). The value must be in range [0.02,0.98]. The default is 0.75. Float* K — Optional. Non-negative constant value to detect mild or stronger outliers. The default value is 1.5. Float* Returned value Returns an array of the same length as the input array where each value represents score of possible anomaly of corresponding element in the series. A non-zero score indicates a possible anomaly. Array(Float32) Examples Basic outlier detection sql title=Query SELECT seriesOutliersDetectTukey([-3, 2, 15, 3, 5, 6, 4, 5, 12, 45, 12, 3, 3, 4, 5, 6]) AS print_0 response title=Response ┌───────────print_0─────────────────┐ │[0,0,0,0,0,0,0,0,0,27,0,0,0,0,0,0] │ └───────────────────────────────────┘ Custom parameters outlier detection sql title=Query SELECT seriesOutliersDetectTukey([-3, 2, 15, 3, 5, 6, 4.50, 5, 12, 45, 12, 3.40, 3, 4, 5, 6], 0.2, 0.8, 1.5) AS print_0
{"source_file": "time-series-functions.md"}
[ -0.046849872916936874, 0.012982827611267567, 0.026064254343509674, -0.01166880689561367, -0.022284364327788353, -0.08691385388374329, -0.017302241176366806, 0.02362801507115364, 0.03532766178250313, -0.02366046793758869, 0.06773870438337326, -0.04745360463857651, 0.009736210107803345, -0.0...
ca6f2907-469b-436a-b05e-1e81b64c6b1a
Custom parameters outlier detection sql title=Query SELECT seriesOutliersDetectTukey([-3, 2, 15, 3, 5, 6, 4.50, 5, 12, 45, 12, 3.40, 3, 4, 5, 6], 0.2, 0.8, 1.5) AS print_0 response title=Response ┌─print_0──────────────────────────────┐ │ [0,0,0,0,0,0,0,0,0,19.5,0,0,0,0,0,0] │ └──────────────────────────────────────┘ seriesPeriodDetectFFT {#seriesPeriodDetectFFT} Introduced in: v23.12 Finds the period of the given series data using FFT - Fast Fourier transform Syntax sql seriesPeriodDetectFFT(series) Arguments series — An array of numeric values. Array((U)Int8/16/32/64) or Array(Float*) Returned value Returns a real value equal to the period of series data. NaN when number of data points are less than four. Float64 Examples Period detection with simple pattern sql title=Query SELECT seriesPeriodDetectFFT([1, 4, 6, 1, 4, 6, 1, 4, 6, 1, 4, 6, 1, 4, 6, 1, 4, 6, 1, 4, 6]) AS print_0 response title=Response ┌───────────print_0──────┐ │ 3 │ └────────────────────────┘ Period detection with complex pattern sql title=Query SELECT seriesPeriodDetectFFT(arrayMap(x -> abs((x % 6) - 3), range(1000))) AS print_0 response title=Response ┌─print_0─┐ │ 6 │ └─────────┘ timeSeriesFromGrid {#timeSeriesFromGrid} Introduced in: v25.8 Converts an array of values [x1, x2, x3, ...] to an array of tuples [(start_timestamp, x1), (start_timestamp + step, x2), (start_timestamp + 2 * step, x3), ...] . The current timestamp is increased by step until it becomes greater than end_timestamp If the number of the values doesn't match the number of the timestamps, the function throws an exception. NULL values in [x1, x2, x3, ...] are skipped but the current timestamp is still incremented. For example, for [value1, NULL, x2] the function returns [(start_timestamp, x1), (start_timestamp + 2 * step, x2)] . Syntax sql timeSeriesFromGrid(start_timestamp, end_timestamp, step, values) Arguments start_timestamp — Start of the grid. DateTime64 or DateTime or UInt32 end_timestamp — End of the grid. DateTime64 or DateTime or UInt32 step — Step of the grid in seconds Decimal64 or Decimal32 or UInt32/64 values — Array of values Array(Float*) or Array(Nullable(Float*)) Returned value Returns values from the source array of values combined with timestamps on a regular time grid described by start_timestamp and step . Array(Tuple(DateTime64, Float64)) Examples Usage example sql title=Query SELECT timeSeriesFromGrid('2025-06-01 00:00:00'::DateTime64(3), '2025-06-01 00:01:30.000'::DateTime64(3), 30, [10, 20, NULL, 30]) AS result; response title=Response ┌─────────────────────────────────────────────result─────────────────────────────────────────────┐ │ [('2025-06-01 00:00:00.000',10),('2025-06-01 00:00:30.000',20),('2025-06-01 00:01:30.000',30)] │ └────────────────────────────────────────────────────────────────────────────────────────────────┘
{"source_file": "time-series-functions.md"}
[ -0.03917144238948822, -0.039236538112163544, -0.029917150735855103, 0.019140809774398804, 0.009052861481904984, -0.0756896361708641, 0.03710698336362839, -0.03264098986983299, 0.01683434657752514, -0.00877968966960907, -0.002606726484373212, -0.056019533425569534, 0.0043111140839755535, -0...
1544e861-a465-4167-b3d3-cc5296fd477e
timeSeriesIdToTags {#timeSeriesIdToTags} Introduced in: v25.8 Finds tags associated with the specified identifier of a time series. Syntax sql timeSeriesIdToTags(id) Arguments id — Identifier of a time series. UInt64 or UInt128 or UUID or FixedString(16) Returned value Returns an array of pairs (tag_name, tag_value). Array(Tuple(String, String)) Examples Example sql title=Query SELECT timeSeriesStoreTags(8374283493092, [('region', 'eu'), ('env', 'dev')], '__name__', 'http_requests_count') AS id, timeSeriesIdToTags(id) response title=Response 8374283493092 [('__name__', ''http_requests_count''), ('env', 'dev'), ('region', 'eu')] timeSeriesIdToTagsGroup {#timeSeriesIdToTagsGroup} Introduced in: v25.8 Converts the specified identifier of a time series to its group index. Group indices are numbers 0, 1, 2, 3 associated with each unique set of tags in the context of the currently executed query. Syntax sql timeSeriesIdToTagsGroup(id) Arguments id — Identifier of a time series. UInt64 or UInt128 or UUID or FixedString(16) Returned value Returns a group index associated with this set of tags. UInt64 Examples Example sql title=Query SELECT timeSeriesStoreTags(8374283493092, [('region', 'eu'), ('env', 'dev')], '__name__', 'http_requests_count') AS id, timeSeriesIdToTagsGroup(id) response title=Response 8374283493092 0 timeSeriesRange {#timeSeriesRange} Introduced in: v25.8 Generates a range of timestamps [start_timestamp, start_timestamp + step, start_timestamp + 2 * step, ..., end_timestamp]. If start_timestamp is equal to end_timestamp , the function returns a 1-element array containing [start_timestamp] . Function timeSeriesRange() is similar to function range . Syntax sql timeSeriesRange(start_timestamp, end_timestamp, step) Arguments start_timestamp — Start of the range. DateTime64 or DateTime or UInt32 end_timestamp — End of the range. DateTime64 or DateTime or UInt32 step — Step of the range in seconds UInt32/64 or Decimal32/64 Returned value Returns a range of timestamps. Array(DateTime64) Examples Usage example sql title=Query SELECT timeSeriesRange('2025-06-01 00:00:00'::DateTime64(3), '2025-06-01 00:01:00'::DateTime64(3), 30) response title=Response ┌────────────────────────────────────result─────────────────────────────────────────┐ │ ['2025-06-01 00:00:00.000', '2025-06-01 00:00:30.000', '2025-06-01 00:01:00.000'] │ └───────────────────────────────────────────────────────────────────────────────────┘ timeSeriesStoreTags {#timeSeriesStoreTags} Introduced in: v25.8 Stores mapping between the identifier of a time series and its tags in the query context, so that function timeSeriesIdToTags() can extract these tags later. Syntax sql timeSeriesStoreTags(id, tags_array, separate_tag_name_1, separate_tag_value_1, ...) Arguments
{"source_file": "time-series-functions.md"}
[ 0.017101965844631195, 0.03833770751953125, -0.054242853075265884, 0.007901880890130997, -0.018176553770899773, -0.07574599981307983, 0.02754059247672558, -0.02630494348704815, 0.013773596845567226, -0.018170133233070374, -0.03269599750638008, -0.07101257890462875, -0.01611470617353916, -0....
91220b60-c7b6-4ef8-8f60-df52dd1abadd
Syntax sql timeSeriesStoreTags(id, tags_array, separate_tag_name_1, separate_tag_value_1, ...) Arguments id — Identifier of a time series. UInt64 or UInt128 or UUID or FixedString(16) tags_array — Array of pairs (tag_name, tag_value). Array(Tuple(String, String)) or NULL separate_tag_name_i — The name of a tag. String or FixedString separate_tag_value_i — The value of a tag. String or FixedString or Nullable(String) Returned value Returns the first argument, i.e. the identifier of a time series. Examples Example sql title=Query SELECT timeSeriesStoreTags(8374283493092, [('region', 'eu'), ('env', 'dev')], '__name__', 'http_requests_count') response title=Response 8374283493092 timeSeriesTagsGroupToTags {#timeSeriesTagsGroupToTags} Introduced in: v25.8 Finds tags associated with a group index. Group indices are numbers 0, 1, 2, 3 associated with each unique set of tags in the context of the currently executed query. Syntax sql timeSeriesTagsGroupToTags(group) Arguments group — Group index associated with a time series. UInt64 Returned value Array of pairs (tag_name, tag_value). Array(Tuple(String, String)) Examples Example sql title=Query SELECT timeSeriesStoreTags(8374283493092, [('region', 'eu'), ('env', 'dev')], '__name__', 'http_requests_count') AS id, timeSeriesIdToTagsGroup(id) AS group, timeSeriesTagsGroupToTags(group) response title=Response 8374283493092 0 [('__name__', ''http_requests_count''), ('env', 'dev'), ('region', 'eu')]
{"source_file": "time-series-functions.md"}
[ -0.0064779361709952354, 0.05217543616890907, -0.07133490592241287, 0.019633658230304718, -0.034067295491695404, -0.06074031442403793, 0.0542142428457737, 0.013108554296195507, 0.0196555033326149, -0.011800614185631275, -0.030842676758766174, -0.08038610219955444, -0.03788435831665993, -0.0...
d176dab6-ed30-4559-8a38-c01572be82e4
description: 'Documentation for functions used to generate random numbers' sidebar_label: 'Random number' slug: /sql-reference/functions/random-functions title: 'Functions for generating random numbers' doc_type: 'reference' Functions for generating random numbers All functions in this section accept zero or one arguments. The only use of the argument (if provided) is to prevent common subexpression elimination such that two different executions within a row of the same random function return different random values. Related content Guide: Generating random data in ClickHouse Blog: Generating random data in ClickHouse :::note The random numbers are generated by non-cryptographic algorithms. ::: :::note The documentation below is generated from the system.functions system table. ::: fuzzBits {#fuzzBits} Introduced in: v20.5 Flips the bits of the input string s , with probability p for each bit. Syntax sql fuzzBits(s, p) Arguments s — String or FixedString to perform bit fuzzing on String or FixedString p — Probability of flipping each bit as a number between 0.0 and 1.0 Float* Returned value Returns a Fuzzed string with same type as s . String or FixedString Examples Usage example sql title=Query SELECT fuzzBits(materialize('abacaba'), 0.1) FROM numbers(3) response title=Response ┌─fuzzBits(materialize('abacaba'), 0.1)─┐ │ abaaaja │ │ a*cjab+ │ │ aeca2A │ └───────────────────────────────────────┘ rand {#rand} Introduced in: v1.1 Returns a random UInt32 number with uniform distribution. Uses a linear congruential generator with an initial state obtained from the system, which means that while it appears random, it's not truly random and can be predictable if the initial state is known. For scenarios where true randomness is crucial, consider using alternative methods like system-level calls or integrating with external libraries. Syntax sql rand([x]) Aliases : rand32 Arguments x — Optional and ignored. The only purpose of the argument is to prevent common subexpression elimination when the same function call is used multiple times in a query. Any Returned value Returns a random number of type UInt32 . UInt32 Examples Usage example sql title=Query SELECT rand(); response title=Response 1569354847 rand64 {#rand64} Introduced in: v1.1 Returns a random distributed UInt64 number with uniform distribution. Uses a linear congruential generator with an initial state obtained from the system, which means that while it appears random, it's not truly random and can be predictable if the initial state is known. For scenarios where true randomness is crucial, consider using alternative methods like system-level calls or integrating with external libraries. Syntax sql rand64([x]) Arguments
{"source_file": "random-functions.md"}
[ -0.055971790105104446, 0.01225697435438633, -0.08786847442388535, 0.0140931261703372, -0.06998597830533981, -0.08990531414747238, 0.14248555898666382, -0.020076274871826172, -0.02543024532496929, -0.0159678366035223, 0.01555836945772171, -0.05257445201277733, 0.12624791264533997, -0.102260...
5d8cd1d7-18bd-4b1b-abd4-b470a27f47de
Syntax sql rand64([x]) Arguments x — Optional and ignored. The only purpose of the argument is to prevent common subexpression elimination when the same function call is used multiple times in a query. Any Returned value Returns a random UInt64 number with uniform distribution. UInt64 Examples Usage example sql title=Query SELECT rand64(); response title=Response 15030268859237645412 randBernoulli {#randBernoulli} Introduced in: v22.10 Returns a random Float64 number drawn from a Bernoulli distribution . Syntax sql randBernoulli(probability[, x]) Arguments probability — The probability of success as a value between 0 and 1 . Float64 x — Optional and ignored. The only purpose of the argument is to prevent common subexpression elimination when the same function call is used multiple times in a query. Any Returned value Returns a random Float64 number drawn from the specified Bernoulli distribution. UInt64 Examples Usage example sql title=Query SELECT randBernoulli(.75) FROM numbers(5) response title=Response ┌─randBernoulli(0.75)─┐ │ 1 │ │ 1 │ │ 0 │ │ 1 │ │ 1 │ └─────────────────────┘ randBinomial {#randBinomial} Introduced in: v22.10 Returns a random Float64 number drawn from a binomial distribution . Syntax sql randBinomial(experiments, probability[, x]) Arguments experiments — The number of experiments UInt64 probability — The probability of success in each experiment as a value between 0 and 1 Float64 x — Optional and ignored. The only purpose of the argument is to prevent common subexpression elimination when the same function call is used multiple times in a query. Any Returned value Returns a random Float64 number drawn from the specified binomial distribution. UInt64 Examples Usage example sql title=Query SELECT randBinomial(100, .75) FROM numbers(5) response title=Response ┌─randBinomial(100, 0.75)─┐ │ 74 │ │ 78 │ │ 76 │ │ 77 │ │ 80 │ └─────────────────────────┘ randCanonical {#randCanonical} Introduced in: v22.11 Returns a random distributed Float64 number with uniform distribution between 0 (inclusive) and 1 (exclusive). Syntax sql randCanonical([x]) Arguments x — Optional and ignored. The only purpose of the argument is to prevent common subexpression elimination when the same function call is used multiple times in a query. Any Returned value Returns a random Float64 number. Float64 Examples Usage example sql title=Query SELECT randCanonical(); response title=Response 0.345217890123456 randChiSquared {#randChiSquared} Introduced in: v22.10 Returns a random Float64 number drawn from a chi-square distribution . Syntax sql randChiSquared(degree_of_freedom[, x]) Arguments
{"source_file": "random-functions.md"}
[ -0.017077084630727768, 0.02367647923529148, -0.05189979448914528, 0.022750968113541603, -0.014831101521849632, -0.06928157806396484, 0.10511655360460281, -0.053178220987319946, -0.012316107749938965, -0.008683628402650356, -0.0020606317557394505, -0.03643382340669632, 0.08660802990198135, ...
b64f1ece-1a28-4be0-a9e2-4751c3cdc068
Introduced in: v22.10 Returns a random Float64 number drawn from a chi-square distribution . Syntax sql randChiSquared(degree_of_freedom[, x]) Arguments degree_of_freedom — Degrees of freedom. Float64 x — Optional and ignored. The only purpose of the argument is to prevent common subexpression elimination when the same function call is used multiple times in a query. Any Returned value Returns a random Float64 number drawn from the specified chi-square distribution. Float64 Examples Usage example sql title=Query SELECT randChiSquared(10) FROM numbers(5) response title=Response ┌─randChiSquared(10)─┐ │ 10.015463656521543 │ │ 9.621799919882768 │ │ 2.71785015634699 │ │ 11.128188665931908 │ │ 4.902063104425469 │ └────────────────────┘ randConstant {#randConstant} Introduced in: v1.1 Generates a single random value that remains constant across all rows in the current query execution. This function: - Returns the same random value for every row within a single query - Produces different values across separate query executions It is useful for applying consistent random seeds or identifiers across all rows in a dataset Syntax sql randConstant([x]) Arguments x — Optional and ignored. The only purpose of the argument is to prevent common subexpression elimination when the same function call is used multiple times in a query. Any Returned value Returns a column of type UInt32 containing the same random value in each row. UInt32 Examples Basic usage sql title=Query SELECT randConstant() AS random_value; response title=Response | random_value | |--------------| | 1234567890 | Usage with parameter sql title=Query SELECT randConstant(10) AS random_value; response title=Response | random_value | |--------------| | 9876543210 | randExponential {#randExponential} Introduced in: v22.10 Returns a random Float64 number drawn from an exponential distribution . Syntax sql randExponential(lambda[, x]) Arguments lambda — Rate parameter or lambda value of the distribution Float64 x — Optional and ignored. The only purpose of the argument is to prevent common subexpression elimination when the same function call is used multiple times in a query. Any Returned value Returns a random Float64 number drawn from the specified exponential distribution. Float64 Examples Usage example sql title=Query SELECT randExponential(1/10) FROM numbers(5) response title=Response ┌─randExponential(divide(1, 10))─┐ │ 44.71628934340778 │ │ 4.211013337903262 │ │ 10.809402553207766 │ │ 15.63959406553284 │ │ 1.8148392319860158 │ └────────────────────────────────┘ randFisherF {#randFisherF} Introduced in: v22.10 Returns a random Float64 number drawn from an F-distribution . Syntax sql randFisherF(d1, d2[, x]) Arguments d1 — d1 degree of freedom in X = (S1 / d1) / (S2 / d2) . Float64
{"source_file": "random-functions.md"}
[ -0.034676700830459595, 0.03023187443614006, -0.05052546411752701, 0.05915563926100731, 0.018392644822597504, -0.028995264321565628, 0.06947033107280731, -0.04293868690729141, 0.0015468386700376868, 0.055863264948129654, 0.02105136215686798, -0.017705727368593216, 0.05756888538599014, -0.06...
4cc693aa-e42b-4678-9040-7d4949c912da
Returns a random Float64 number drawn from an F-distribution . Syntax sql randFisherF(d1, d2[, x]) Arguments d1 — d1 degree of freedom in X = (S1 / d1) / (S2 / d2) . Float64 d2 — d2 degree of freedom in X = (S1 / d1) / (S2 / d2) . Float64 x — Optional and ignored. The only purpose of the argument is to prevent common subexpression elimination when the same function call is used multiple times in a query. Any Returned value Returns a random Float64 number drawn from the specified F-distribution Float64 Examples Usage example sql title=Query SELECT randFisherF(10, 3) FROM numbers(5) response title=Response ┌─randFisherF(10, 20)─┐ │ 0.7204609609506184 │ │ 0.9926258472572916 │ │ 1.4010752726735863 │ │ 0.34928401507025556 │ │ 1.8216216009473598 │ └─────────────────────┘ randLogNormal {#randLogNormal} Introduced in: v22.10 Returns a random Float64 number drawn from a log-normal distribution . Syntax sql randLogNormal(mean, stddev[, x]) Arguments mean — The mean value of distribution. Float64 stddev — The standard deviation of the distribution. Float64 x — Optional and ignored. The only purpose of the argument is to prevent common subexpression elimination when the same function call is used multiple times in a query. Any Returned value Returns a random Float64 number drawn from the specified log-normal distribution. Float64 Examples Usage example sql title=Query SELECT randLogNormal(100, 5) FROM numbers(5) response title=Response ┌─randLogNormal(100, 5)─┐ │ 1.295699673937363e48 │ │ 9.719869109186684e39 │ │ 6.110868203189557e42 │ │ 9.912675872925529e39 │ │ 2.3564708490552458e42 │ └───────────────────────┘ randNegativeBinomial {#randNegativeBinomial} Introduced in: v22.10 Returns a random Float64 number drawn from a negative binomial distribution . Syntax sql randNegativeBinomial(experiments, probability[, x]) Arguments experiments — The number of experiments. UInt64 probability — The probability of failure in each experiment as a value between 0 and 1 . [ Float64`](/sql-reference/data-types/float) x — Optional and ignored. The only purpose of the argument is to prevent common subexpression elimination when the same function call is used multiple times in a query. Any Returned value Returns a random Float64 number drawn from the specified negative binomial distribution UInt64 Examples Usage example sql title=Query SELECT randNegativeBinomial(100, .75) FROM numbers(5) response title=Response ┌─randNegativeBinomial(100, 0.75)─┐ │ 33 │ │ 32 │ │ 39 │ │ 40 │ │ 50 │ └─────────────────────────────────┘ randNormal {#randNormal} Introduced in: v22.10 Returns a random Float64 number drawn from a normal distribution . Syntax sql randNormal(mean, stddev[, x]) Arguments
{"source_file": "random-functions.md"}
[ -0.02588091976940632, 0.010048815049231052, -0.05482525750994682, -0.029758507385849953, 0.03394239395856857, -0.07203102856874466, 0.05582503229379654, -0.006413323804736137, 0.013940983451902866, 0.010972356423735619, -0.010281174443662167, -0.0790630653500557, 0.006685770582407713, -0.0...
a23e2fa2-eea9-4537-bedf-6e62713de35c
randNormal {#randNormal} Introduced in: v22.10 Returns a random Float64 number drawn from a normal distribution . Syntax sql randNormal(mean, stddev[, x]) Arguments mean — The mean value of distribution Float64 stddev — The standard deviation of the distribution Float64 x — Optional and ignored. The only purpose of the argument is to prevent common subexpression elimination when the same function call is used multiple times in a query. Any Returned value Returns a random Float64 number drawn from the specified normal distribution. Float64 Examples Usage example sql title=Query SELECT randNormal(10, 2) FROM numbers(5) response title=Response ┌──randNormal(10, 2)─┐ │ 13.389228911709653 │ │ 8.622949707401295 │ │ 10.801887062682981 │ │ 4.5220192605895315 │ │ 10.901239123982567 │ └────────────────────┘ randPoisson {#randPoisson} Introduced in: v22.10 Returns a random Float64 number drawn from a Poisson distribution distribution. Syntax sql randPoisson(n[, x]) Arguments n — The mean number of occurrences. UInt64 x — Optional and ignored. The only purpose of the argument is to prevent common subexpression elimination when the same function call is used multiple times in a query. Any Returned value Returns a random Float64 number drawn from the specified Poisson distribution. UInt64 Examples Usage example sql title=Query SELECT randPoisson(10) FROM numbers(5) response title=Response ┌─randPoisson(10)─┐ │ 8 │ │ 8 │ │ 7 │ │ 10 │ │ 6 │ └─────────────────┘ randStudentT {#randStudentT} Introduced in: v22.10 Returns a random Float64 number drawn from a Student's t-distribution . Syntax sql randStudentT(degree_of_freedom[, x]) Arguments degree_of_freedom — Degrees of freedom. Float64 x — Optional and ignored. The only purpose of the argument is to prevent common subexpression elimination when the same function call is used multiple times in a query. Any Returned value Returns a random Float64 number drawn from the specified Student's t-distribution. Float64 Examples Usage example sql title=Query SELECT randStudentT(10) FROM numbers(5) response title=Response ┌─────randStudentT(10)─┐ │ 1.2217309938538725 │ │ 1.7941971681200541 │ │ -0.28192176076784664 │ │ 0.2508897721303792 │ │ -2.7858432909761186 │ └──────────────────────┘ randUniform {#randUniform} Introduced in: v22.10 Returns a random Float64 number drawn uniformly from the interval $[\min, \max]$. Syntax sql randUniform(min, max[, x]) Arguments min — Left boundary of the range (inclusive). Float64 max — Right boundary of the range (inclusive). Float64 x — Optional and ignored. The only purpose of the argument is to prevent common subexpression elimination when the same function call is used multiple times in a query. Any Returned value
{"source_file": "random-functions.md"}
[ -0.012090214528143406, 0.0041155703365802765, -0.04267214238643646, 0.011936124414205551, -0.02235780842602253, -0.08149923384189606, 0.07531768828630447, -0.03153609856963158, 0.03487120196223259, -0.004362805280834436, 0.05833299830555916, 0.021086379885673523, 0.061094220727682114, -0.0...
02a89108-1fb4-43a7-8001-86e9958fc578
x — Optional and ignored. The only purpose of the argument is to prevent common subexpression elimination when the same function call is used multiple times in a query. Any Returned value Returns a random number drawn uniformly from the interval formed by min and max . Float64 Examples Usage example sql title=Query SELECT randUniform(5.5, 10) FROM numbers(5) response title=Response ┌─randUniform(5.5, 10)─┐ │ 8.094978491443102 │ │ 7.3181248914450885 │ │ 7.177741903868262 │ │ 6.483347380953762 │ │ 6.122286382885112 │ └──────────────────────┘ randomFixedString {#randomFixedString} Introduced in: v20.5 Generates a random fixed-size string with the specified number of character. The returned characters are not necessarily ASCII characters, i.e. they may not be printable. Syntax sql randomFixedString(length) Arguments length — Length of the string in bytes. UInt* Returned value Returns a string filled with random bytes. FixedString Examples Usage example sql title=Query SELECT randomFixedString(13) AS rnd, toTypeName(rnd) response title=Response ┌─rnd──────┬─toTypeName(randomFixedString(13))─┐ │ j▒h㋖HɨZ'▒ │ FixedString(13) │ └──────────┴───────────────────────────────────┘ randomPrintableASCII {#randomPrintableASCII} Introduced in: v20.1 Generates a random ASCII string with the specified number of characters. If you pass length < 0 , the behavior of the function is undefined. Syntax sql randomPrintableASCII(length[, x]) Arguments length — String length in bytes. (U)Int* x — Optional and ignored. The only purpose of the argument is to prevent common subexpression elimination when the same function call is used multiple times in a query. Any Returned value Returns a string with a random set of ASCII printable characters. String Examples Usage example sql title=Query SELECT number, randomPrintableASCII(30) AS str, length(str) FROM system.numbers LIMIT 3 response title=Response ┌─number─┬─str────────────────────────────┬─length(randomPrintableASCII(30))─┐ │ 0 │ SuiCOSTvC0csfABSw=UcSzp2.`rv8x │ 30 │ │ 1 │ 1Ag NlJ &RCN:*>HVPG;PE-nO"SUFD │ 30 │ │ 2 │ /"+<"with:=LjJ Vm!c&hI*m#XTfzz │ 30 │ └────────┴────────────────────────────────┴──────────────────────────────────┘ randomString {#randomString} Introduced in: v20.5 Generates a random string with the specified number of characters. The returned characters are not necessarily ASCII characters, i.e. they may not be printable. Syntax sql randomString(length[, x]) Arguments length — Length of the string in bytes. (U)Int* x — Optional and ignored. The only purpose of the argument is to prevent common subexpression elimination when the same function call is used multiple times in a query. Any Returned value
{"source_file": "random-functions.md"}
[ -0.0467475987970829, 0.04902354255318642, -0.035206280648708344, 0.040907345712184906, -0.0393042266368866, -0.022103484719991684, 0.12616829574108124, 0.026995833963155746, 0.014954417943954468, -0.003524876432493329, -0.004130742512643337, -0.02859167382121086, 0.07847371697425842, -0.06...
d64f172e-377e-4390-b077-41a9794c6f00
x — Optional and ignored. The only purpose of the argument is to prevent common subexpression elimination when the same function call is used multiple times in a query. Any Returned value Returns a string filled with random bytes. String Examples Usage example sql title=Query SELECT randomString(5) AS str FROM numbers(2) response title=Response ��� �v6B� randomStringUTF8 {#randomStringUTF8} Introduced in: v20.5 Generates a random UTF-8 string with the specified number of codepoints. No codepoints from unassigned planes (planes 4 to 13) are returned. It is still possible that the client interacting with ClickHouse server is not able to display the produced UTF-8 string correctly. Syntax sql randomStringUTF8(length) Arguments length — Length of the string in code points. (U)Int* Returned value Returns a string filled with random UTF-8 codepoints. String Examples Usage example sql title=Query SELECT randomStringUTF8(13) response title=Response ┌─randomStringUTF8(13)─┐ │ 𘤗𙉝д兠庇󡅴󱱎󦐪􂕌𔊹𓰛 │ └──────────────────────┘
{"source_file": "random-functions.md"}
[ -0.0069833542220294476, -0.006070567294955254, -0.02837952971458435, -0.019738344475626945, -0.07784616947174072, 0.015044753439724445, 0.13120068609714508, -0.05122455209493637, 0.03217426314949989, -0.06518065929412842, 0.010104188695549965, -0.02771998941898346, 0.0792771652340889, -0.0...
b844110b-6708-4b7d-b6ed-c005b5a353e1
description: 'Documentation for Regular Functions' sidebar_label: 'Overview' sidebar_position: 1 slug: /sql-reference/functions/overview title: 'Regular Functions' doc_type: 'reference' Regular functions There are at least* two types of functions - regular functions (they are just called "functions") and aggregate functions. These are completely different concepts. Regular functions work as if they are applied to each row separately (for each row, the result of the function does not depend on the other rows). Aggregate functions accumulate a set of values from various rows (i.e. they depend on the entire set of rows). In this section we discuss regular functions. For aggregate functions, see the section "Aggregate functions". :::note There is a third type of function that the 'arrayJoin' function belongs to. And table functions can also be mentioned separately. ::: Strong Typing {#strong-typing} In contrast to standard SQL, ClickHouse has strong typing. In other words, it does not make implicit conversions between types. Each function works for a specific set of types. This means that sometimes you need to use type conversion functions. Common Subexpression Elimination {#common-subexpression-elimination} All expressions in a query that have the same AST (the same record or same result of syntactic parsing) are considered to have identical values. Such expressions are concatenated and executed once. Identical subqueries are also eliminated this way. Types of Results {#types-of-results} All functions return a single value as the result (not several values, and not zero values). The type of result is usually defined only by the types of arguments, not by the values. Exceptions are the tupleElement function (the a.N operator), and the toFixedString function. Constants {#constants} For simplicity, certain functions can only work with constants for some arguments. For example, the right argument of the LIKE operator must be a constant. Almost all functions return a constant for constant arguments. The exception is functions that generate random numbers. The 'now' function returns different values for queries that were run at different times, but the result is considered a constant, since constancy is only important within a single query. A constant expression is also considered a constant (for example, the right half of the LIKE operator can be constructed from multiple constants). Functions can be implemented in different ways for constant and non-constant arguments (different code is executed). But the results for a constant and for a true column containing only the same value should match each other. NULL Processing {#null-processing} Functions have the following behaviors: If at least one of the arguments of the function is NULL , the function result is also NULL .
{"source_file": "overview.md"}
[ -0.04915427044034004, -0.030578920617699623, 0.046795982867479324, 0.01815040595829487, -0.039436619728803635, 0.005928170867264271, -0.014124587178230286, 0.01766803488135338, -0.006210912484675646, 0.0072206174954771996, -0.016497498378157616, 0.03790590912103653, 0.029496772214770317, -...
87f7547e-4646-45ac-b1bb-5e3dbaaea312
NULL Processing {#null-processing} Functions have the following behaviors: If at least one of the arguments of the function is NULL , the function result is also NULL . Special behavior that is specified individually in the description of each function. In the ClickHouse source code, these functions have UseDefaultImplementationForNulls=false . Constancy {#constancy} Functions can't change the values of their arguments – any changes are returned as the result. Thus, the result of calculating separate functions does not depend on the order in which the functions are written in the query. Higher-order functions {#higher-order-functions} -> operator and lambda(params, expr) functions {#arrow-operator-and-lambda} Higher-order functions can only accept lambda functions as their functional argument. To pass a lambda function to a higher-order function use -> operator. The left side of the arrow has a formal parameter, which is any ID, or multiple formal parameters – any IDs in a tuple. The right side of the arrow has an expression that can use these formal parameters, as well as any table columns. Examples: python x -> 2 * x str -> str != Referer A lambda function that accepts multiple arguments can also be passed to a higher-order function. In this case, the higher-order function is passed several arrays of identical length that these arguments will correspond to. For some functions the first argument (the lambda function) can be omitted. In this case, identical mapping is assumed. User Defined Functions (UDFs) {#user-defined-functions-udfs} ClickHouse supports user-defined functions. See UDFs .
{"source_file": "overview.md"}
[ -0.06347350776195526, -0.030355557799339294, -0.039247605949640274, 0.013427230529487133, -0.04332411661744118, -0.08676119893789291, -0.023297274485230446, -0.03623117133975029, -0.0004318639694247395, 0.01232799980789423, 0.04190367832779884, 0.019144315272569656, 0.024093428626656532, -...
2e98ff50-462b-4fae-9e4f-9576578a9ae3
description: 'Documentation for NumericIndexedVector and Its Functions' sidebar_label: 'NumericIndexedVector' slug: /sql-reference/functions/numeric-indexed-vector-functions title: 'NumericIndexedVector Functions' doc_type: 'reference' NumericIndexedVector NumericIndexedVector is an abstract data structure that encapsulates a vector and implements vector aggregating and pointwise operations. Bit-Sliced Index is its storage method. For theoretical basis and usage scenarios, refer to the paper Large-Scale Metric Computation in Online Controlled Experiment Platform . BSI {#bit-sliced-index} In the BSI (Bit-Sliced Index) storage method, the data is stored in Bit-Sliced Index and then compressed using Roaring Bitmap . Aggregating operations and pointwise operations are directly on the compressed data, which can significantly improve the efficiency of storage and query. A vector contains indices and their corresponding values. The following are some characteristics and constraints of this data structure in BSI storage mode: The index type can be one of UInt8 , UInt16 , or UInt32 . Note: Considering the performance of 64-bit implementation of Roaring Bitmap, BSI format does not support UInt64 / Int64 . The value type can be one of Int8 , Int16 , Int32 , Int64 , UInt8 , UInt16 , UInt32 , UInt64 , Float32 , or Float64 . Note: The value type does not automatically expand. For example, if you use UInt8 as the value type, any sum that exceeds the capacity of UInt8 will result in an overflow rather than being promoted to a higher type; similarly, operations on integers will yield integer results (e.g., division will not automatically convert to a floating-point result). Therefore, it is important to plan and design the value type ahead of time. In real-world scenarios, floating-point types ( Float32 / Float64 ) are commonly used. Only two vectors with the same index type and value type can perform operations. The underlying storage uses Bit-Sliced Index, with bitmap storing indexes. Roaring Bitmap is used as the specific implementation of bitmap. A best practice is to concentrate the index in several Roaring Bitmap containers as much as possible to maximize compression and query performance. The Bit-Sliced Index mechanism converts value into binary. For floating-point types, the conversion uses fixed-point representation, which may lead to precision loss. The precision can be adjusted by customizing the number of bits used for the fractional part, default is 24 bits, which is sufficient for most scenarios. You can customize the number of integer bits and fractional bits when constructing NumericIndexedVector using aggregate function groupNumericIndexedVector with -State .
{"source_file": "numeric-indexed-vector-functions.md"}
[ -0.031771935522556305, 0.02280122973024845, -0.044206153601408005, 0.04303374141454697, -0.013657432049512863, -0.05716593191027641, -0.03320984169840813, -0.014587982557713985, -0.012933510355651379, -0.054750073701143265, -0.05915705859661102, 0.041069287806749344, 0.0058492389507591724, ...
45a8a728-fc4a-447e-a066-56ad2fb544b2
There are three cases for indices: non-zero value, zero value and non-existent. In NumericIndexedVector, only non-zero value and zero value will be stored. In addition, in pointwise operations between two NumericIndexedVectors, the value of non-existent index will be treated as 0. In the division scenario, the result is zero when the divisor is zero. Create a numericIndexedVector object {#create-numeric-indexed-vector-object} There are two ways to create this structure: one is to use the aggregate function groupNumericIndexedVector with -State . You can add suffix -if to accept an additional condition. The aggregate function will only process the rows that trigger the condition. The other is to build it from a map using numericIndexedVectorBuild . The groupNumericIndexedVectorState function allows customization of the number of integer and fractional bits through parameters, while numericIndexedVectorBuild does not. groupNumericIndexedVector {#group-numeric-indexed-vector} Constructs a NumericIndexedVector from two data columns and returns the sum of all values as a Float64 type. If the suffix State is added, it returns a NumericIndexedVector object. Syntax sql groupNumericIndexedVectorState(col1, col2) groupNumericIndexedVectorState(type, integer_bit_num, fraction_bit_num)(col1, col2) Parameters type : String, optional. Specifies the storage format. Currently, only 'BSI' is supported. integer_bit_num : UInt32 , optional. Effective under the 'BSI' storage format, this parameter indicates the number of bits used for the integer part. When the index type is an integer type, the default value corresponds to the number of bits used to store the index. For example, if the index type is UInt16, the default integer_bit_num is 16. For Float32 and Float64 index types, the default value of integer_bit_num is 40, so the integer part of the data that can be represented is in the range [-2^39, 2^39 - 1] . The legal range is [0, 64] . fraction_bit_num : UInt32 , optional. Effective under the 'BSI' storage format, this parameter indicates the number of bits used for the fractional part. When the value type is an integer, the default value is 0; when the value type is Float32 or Float64 types, the default value is 24. The valid range is [0, 24] . There is also a constraint that the valid range of integer_bit_num + fraction_bit_num is [0, 64]. col1 : The index column. Supported types: UInt8 / UInt16 / UInt32 / Int8 / Int16 / Int32 . col2 : The value column. Supported types: Int8 / Int16 / Int32 / Int64 / UInt8 / UInt16 / UInt32 / UInt64 / Float32 / Float64 . Return value A Float64 value representing the sum of all values. Example Test data: text UserID PlayTime 1 10 2 20 3 30 Query & Result: ```sql SELECT groupNumericIndexedVector(UserID, PlayTime) AS num FROM t; ┌─num─┐ │ 60 │ └─────┘
{"source_file": "numeric-indexed-vector-functions.md"}
[ -0.035790424793958664, 0.024533012881875038, -0.025580910965800285, 0.016720514744520187, 0.020290076732635498, 0.0028832871466875076, -0.016602780669927597, -0.046658243983983994, 0.04083260893821716, -0.004245269577950239, -0.031193295493721962, -0.049071893095970154, 0.004730653949081898,...
64f88a18-c385-4d82-b73e-a2e48df97125
Example Test data: text UserID PlayTime 1 10 2 20 3 30 Query & Result: ```sql SELECT groupNumericIndexedVector(UserID, PlayTime) AS num FROM t; ┌─num─┐ │ 60 │ └─────┘ SELECT groupNumericIndexedVectorState(UserID, PlayTime) as res, toTypeName(res), numericIndexedVectorAllValueSum(res) FROM t; ┌─res─┬─toTypeName(res)─────────────────────────────────────────────┬─numericIndexedVectorAllValueSum(res)──┐ │ │ AggregateFunction(groupNumericIndexedVector, UInt8, UInt8) │ 60 │ └─────┴─────────────────────────────────────────────────────────────┴───────────────────────────────────────┘ SELECT groupNumericIndexedVectorStateIf(UserID, PlayTime, day = '2025-04-22') as res, toTypeName(res), numericIndexedVectorAllValueSum(res) FROM t; ┌─res─┬─toTypeName(res)────────────────────────────────────────────┬─numericIndexedVectorAllValueSum(res)──┐ │ │ AggregateFunction(groupNumericIndexedVector, UInt8, UInt8) │ 30 │ └─────┴────────────────────────────────────────────────────────────┴───────────────────────────────────────┘ SELECT groupNumericIndexedVectorStateIf('BSI', 32, 0)(UserID, PlayTime, day = '2025-04-22') as res, toTypeName(res), numericIndexedVectorAllValueSum(res) FROM t; ┌─res─┬─toTypeName(res)──────────────────────────────────────────────────────────┬─numericIndexedVectorAllValueSum(res)──┐ │ │ AggregateFunction('BSI', 32, 0)(groupNumericIndexedVector, UInt8, UInt8) │ 30 │ └─────┴──────────────────────────────────────────────────────────────────────────┴───────────────────────────────────────┘ ``` :::note The documentation below is generated from the system.functions system table. ::: numericIndexedVectorAllValueSum {#numericIndexedVectorAllValueSum} Introduced in: v25.7 Returns the sum of all values in the numericIndexedVector. Syntax sql numericIndexedVectorAllValueSum(v) Arguments v — numericIndexedVector Returned value Returns the sum. Float64 Examples Usage example sql title=Query SELECT numericIndexedVectorAllValueSum(numericIndexedVectorBuild(mapFromArrays([1, 2, 3], [10, 20, 30]))) AS res; response title=Response ┌─res─┐ │ 60 │ └─────┘ numericIndexedVectorBuild {#numericIndexedVectorBuild} Introduced in: v25.7 Creates a NumericIndexedVector from a map. The map's keys represent the vector's index and map's value represents the vector's value. Syntax sql numericIndexedVectorBuild(map) Arguments map — A mapping from index to value. Map Returned value Returns a NumericIndexedVector object. AggregateFunction Examples Usage example sql title=Query SELECT numericIndexedVectorBuild(mapFromArrays([1, 2, 3], [10, 20, 30])) AS res, toTypeName(res);
{"source_file": "numeric-indexed-vector-functions.md"}
[ 0.02326441928744316, -0.050978608429431915, 0.005830554757267237, -0.010965308174490929, -0.08802299946546555, 0.11088250577449799, 0.0825154110789299, 0.016739165410399437, -0.002369718858972192, -0.025384092703461647, 0.0106121264398098, -0.0867072343826294, 0.0334511399269104, -0.003281...
6ad40325-942d-4008-a876-ccaba1ec823b
Examples Usage example sql title=Query SELECT numericIndexedVectorBuild(mapFromArrays([1, 2, 3], [10, 20, 30])) AS res, toTypeName(res); response title=Response ┌─res─┬─toTypeName(res)────────────────────────────────────────────┐ │ │ AggregateFunction(groupNumericIndexedVector, UInt8, UInt8) │ └─────┴────────────────────────────────────────────────────────────┘ numericIndexedVectorCardinality {#numericIndexedVectorCardinality} Introduced in: v25.7 Returns the cardinality (number of unique indexes) of the numericIndexedVector. Syntax sql numericIndexedVectorCardinality(v) Arguments v — numericIndexedVector Returned value Returns the number of unique indexes. UInt64 Examples Usage example sql title=Query SELECT numericIndexedVectorCardinality(numericIndexedVectorBuild(mapFromArrays([1, 2, 3], [10, 20, 30]))) AS res; response title=Response ┌─res─┐ │ 3 │ └─────┘ numericIndexedVectorGetValue {#numericIndexedVectorGetValue} Introduced in: v25.7 Retrieves the value corresponding to a specified index from a numericIndexedVector. Syntax sql numericIndexedVectorGetValue(v, i) Arguments v — numericIndexedVector i — The index for which the value is to be retrieved. (U)Int* Returned value A numeric value with the same type as the value type of NumericIndexedVector. (U)Int* or Float* Examples Usage example sql title=Query SELECT numericIndexedVectorGetValue(numericIndexedVectorBuild(mapFromArrays([1, 2, 3], [10, 20, 30])), 3) AS res; response title=Response ┌─res─┐ │ 30 │ └─────┘ numericIndexedVectorPointwiseAdd {#numericIndexedVectorPointwiseAdd} Introduced in: v25.7 Performs pointwise addition between a numericIndexedVector and either another numericIndexedVector or a numeric constant. Syntax sql numericIndexedVectorPointwiseAdd(v1, v2) Arguments v1 — numericIndexedVector v2 — A numeric constant or numericIndexedVector object. (U)Int* or Float* or numericIndexedVector Returned value Returns a new numericIndexedVector object. numericIndexedVector Examples Usage example sql title=Query WITH numericIndexedVectorBuild(mapFromArrays([1, 2, 3], arrayMap(x -> toInt32(x), [10, 20, 30]))) AS vec1, numericIndexedVectorBuild(mapFromArrays([2, 3, 4], arrayMap(x -> toInt32(x), [10, 20, 30]))) AS vec2 SELECT numericIndexedVectorToMap(numericIndexedVectorPointwiseAdd(vec1, vec2)) AS res1, numericIndexedVectorToMap(numericIndexedVectorPointwiseAdd(vec1, 2)) AS res2; response title=Response ┌─res1──────────────────┬─res2─────────────┐ │ {1:10,2:30,3:50,4:30} │ {1:12,2:22,3:32} │ └───────────────────────┴──────────────────┘ numericIndexedVectorPointwiseDivide {#numericIndexedVectorPointwiseDivide} Introduced in: v25.7 Performs pointwise division between a numericIndexedVector and either another numericIndexedVector or a numeric constant. Syntax sql numericIndexedVectorPointwiseDivide(v1, v2) Arguments
{"source_file": "numeric-indexed-vector-functions.md"}
[ 0.028350528329610825, -0.05205181613564491, -0.02565411664545536, 0.039994124323129654, -0.027563516050577164, 0.02996688149869442, 0.00632457435131073, -0.004755417816340923, 0.007330408785492182, -0.024626491591334343, -0.047885261476039886, -0.06912386417388916, 0.041830115020275116, -0...
f36f5389-11a3-451d-afed-16b929c0b98c
Performs pointwise division between a numericIndexedVector and either another numericIndexedVector or a numeric constant. Syntax sql numericIndexedVectorPointwiseDivide(v1, v2) Arguments v1 — numericIndexedVector v2 — A numeric constant or numericIndexedVector object. (U)Int* or Float* or numericIndexedVector Returned value Returns a new numericIndexedVector object. numericIndexedVector Examples Usage example sql title=Query with numericIndexedVectorBuild(mapFromArrays([1, 2, 3], arrayMap(x -> toFloat64(x), [10, 20, 30]))) as vec1, numericIndexedVectorBuild(mapFromArrays([2, 3, 4], arrayMap(x -> toFloat64(x), [10, 20, 30]))) as vec2 SELECT numericIndexedVectorToMap(numericIndexedVectorPointwiseDivide(vec1, vec2)) AS res1, numericIndexedVectorToMap(numericIndexedVectorPointwiseDivide(vec1, 2)) AS res2; response title=Response ┌─res1────────┬─res2────────────┐ │ {2:2,3:1.5} │ {1:5,2:10,3:15} │ └─────────────┴─────────────────┘ numericIndexedVectorPointwiseEqual {#numericIndexedVectorPointwiseEqual} Introduced in: v25.7 Performs pointwise comparison between a numericIndexedVector and either another numericIndexedVector or a numeric constant. The result is a numericIndexedVector containing the indices where the values are equal, with all corresponding values set to 1. Syntax sql numericIndexedVectorPointwiseEqual(v1, v2) Arguments v1 — numericIndexedVector v2 — A numeric constant or numericIndexedVector object. (U)Int* or Float* or numericIndexedVector Returned value Returns a new numericIndexedVector object. numericIndexedVector Examples sql title=Query with numericIndexedVectorBuild(mapFromArrays([1, 2, 3], arrayMap(x -> toFloat64(x), [10, 20, 30]))) as vec1, numericIndexedVectorBuild(mapFromArrays([2, 3, 4], arrayMap(x -> toFloat64(x), [20, 20, 30]))) as vec2 SELECT numericIndexedVectorToMap(numericIndexedVectorPointwiseEqual(vec1, vec2)) AS res1, numericIndexedVectorToMap(numericIndexedVectorPointwiseEqual(vec1, 20)) AS res2; response title=Response ┌─res1──┬─res2──┐ │ {2:1} │ {2:1} │ └───────┴───────┘ numericIndexedVectorPointwiseGreater {#numericIndexedVectorPointwiseGreater} Introduced in: v25.7 Performs pointwise comparison between a numericIndexedVector and either another numericIndexedVector or a numeric constant. The result is a numericIndexedVector containing the indices where the first vector's value is greater than the second vector's value, with all corresponding values set to 1. Syntax sql numericIndexedVectorPointwiseGreater(v1, v2) Arguments v1 — numericIndexedVector v2 — A numeric constant or numericIndexedVector object. (U)Int* or Float* or numericIndexedVector Returned value Returns a new numericIndexedVector object. numericIndexedVector Examples Usage example
{"source_file": "numeric-indexed-vector-functions.md"}
[ 0.07981140911579132, -0.010553778149187565, -0.057047538459300995, -0.03210537135601044, 0.03610291704535484, -0.0001234567171195522, -0.008038481697440147, -0.05495855212211609, -0.0902417004108429, -0.012466220185160637, -0.06124776601791382, -0.07636843621730804, 0.037367116659879684, -...
9e121f38-47eb-40ee-8a3c-a8883486077a
Returned value Returns a new numericIndexedVector object. numericIndexedVector Examples Usage example sql title=Query with numericIndexedVectorBuild(mapFromArrays([1, 2, 3], arrayMap(x -> toFloat64(x), [10, 20, 50]))) as vec1, numericIndexedVectorBuild(mapFromArrays([2, 3, 4], arrayMap(x -> toFloat64(x), [20, 40, 30]))) as vec2 SELECT numericIndexedVectorToMap(numericIndexedVectorPointwiseGreater(vec1, vec2)) AS res1, numericIndexedVectorToMap(numericIndexedVectorPointwiseGreater(vec1, 20)) AS res2; response title=Response ┌─res1──────┬─res2──┐ │ {1:1,3:1} │ {3:1} │ └───────────┴───────┘ numericIndexedVectorPointwiseGreaterEqual {#numericIndexedVectorPointwiseGreaterEqual} Introduced in: v25.7 Performs pointwise comparison between a numericIndexedVector and either another numericIndexedVector or a numeric constant. The result is a numericIndexedVector containing the indices where the first vector's value is greater than or equal to the second vector's value, with all corresponding values set to 1. Syntax sql numericIndexedVectorPointwiseGreaterEqual(v1, v2) Arguments v1 — numericIndexedVector v2 — A numeric constant or numericIndexedVector object. (U)Int* or Float* or numericIndexedVector Returned value Returns a new numericIndexedVector object. numericIndexedVector Examples Usage example sql title=Query with numericIndexedVectorBuild(mapFromArrays([1, 2, 3], arrayMap(x -> toFloat64(x), [10, 20, 50]))) as vec1, numericIndexedVectorBuild(mapFromArrays([2, 3, 4], arrayMap(x -> toFloat64(x), [20, 40, 30]))) as vec2 SELECT numericIndexedVectorToMap(numericIndexedVectorPointwiseGreaterEqual(vec1, vec2)) AS res1, numericIndexedVectorToMap(numericIndexedVectorPointwiseGreaterEqual(vec1, 20)) AS res2; response title=Response ┌─res1──────────┬─res2──────┐ │ {1:1,2:1,3:1} │ {2:1,3:1} │ └───────────────┴───────────┘ numericIndexedVectorPointwiseLess {#numericIndexedVectorPointwiseLess} Introduced in: v25.7 Performs pointwise comparison between a numericIndexedVector and either another numericIndexedVector or a numeric constant. The result is a numericIndexedVector containing the indices where the first vector's value is less than the second vector's value, with all corresponding values set to 1. Syntax sql numericIndexedVectorPointwiseLess(v1, v2) Arguments v1 — numericIndexedVector v2 — A numeric constant or numericIndexedVector object. (U)Int* or Float* or numericIndexedVector Returned value Returns a new numericIndexedVector object. numericIndexedVector Examples Usage example
{"source_file": "numeric-indexed-vector-functions.md"}
[ 0.04755458980798721, -0.01520338375121355, -0.01731906086206436, 0.004496867302805185, -0.007020700257271528, 0.018690746277570724, -0.029690401628613472, -0.03589719906449318, -0.046016063541173935, -0.024513470008969307, -0.0678604245185852, -0.09931480884552002, 0.02661510929465294, -0....
da2743a9-d682-4512-a933-ad63e78d400a
Returned value Returns a new numericIndexedVector object. numericIndexedVector Examples Usage example sql title=Query with numericIndexedVectorBuild(mapFromArrays([1, 2, 3], arrayMap(x -> toFloat64(x), [10, 20, 30]))) as vec1, numericIndexedVectorBuild(mapFromArrays([2, 3, 4], arrayMap(x -> toFloat64(x), [20, 40, 30]))) as vec2 SELECT numericIndexedVectorToMap(numericIndexedVectorPointwiseLess(vec1, vec2)) AS res1, numericIndexedVectorToMap(numericIndexedVectorPointwiseLess(vec1, 20)) AS res2; response title=Response ┌─res1──────┬─res2──┐ │ {3:1,4:1} │ {1:1} │ └───────────┴───────┘ numericIndexedVectorPointwiseLessEqual {#numericIndexedVectorPointwiseLessEqual} Introduced in: v25.7 Performs pointwise comparison between a numericIndexedVector and either another numericIndexedVector or a numeric constant. The result is a numericIndexedVector containing the indices where the first vector's value is less than or equal to the second vector's value, with all corresponding values set to 1. Syntax sql numericIndexedVectorPointwiseLessEqual(v1, v2) Arguments v1 — numericIndexedVector v2 — A numeric constant or numericIndexedVector object (U)Int* or Float* or numericIndexedVector Returned value Returns a new numericIndexedVector object. numericIndexedVector Examples Usage example sql title=Query with numericIndexedVectorBuild(mapFromArrays([1, 2, 3], arrayMap(x -> toFloat64(x), [10, 20, 30]))) as vec1, numericIndexedVectorBuild(mapFromArrays([2, 3, 4], arrayMap(x -> toFloat64(x), [20, 40, 30]))) as vec2 SELECT numericIndexedVectorToMap(numericIndexedVectorPointwiseLessEqual(vec1, vec2)) AS res1, numericIndexedVectorToMap(numericIndexedVectorPointwiseLessEqual(vec1, 20)) AS res2; response title=Response ┌─res1──────────┬─res2──────┐ │ {2:1,3:1,4:1} │ {1:1,2:1} │ └───────────────┴───────────┘ numericIndexedVectorPointwiseMultiply {#numericIndexedVectorPointwiseMultiply} Introduced in: v25.7 Performs pointwise multiplication between a numericIndexedVector and either another numericIndexedVector or a numeric constant. Syntax sql numericIndexedVectorPointwiseMultiply(v1, v2) Arguments v1 — numericIndexedVector v2 — A numeric constant or numericIndexedVector object. (U)Int* or Float* or numericIndexedVector Returned value Returns a new numericIndexedVector object. numericIndexedVector Examples sql title=Query with numericIndexedVectorBuild(mapFromArrays([1, 2, 3], arrayMap(x -> toInt32(x), [10, 20, 30]))) as vec1, numericIndexedVectorBuild(mapFromArrays([2, 3, 4], arrayMap(x -> toInt32(x), [10, 20, 30]))) as vec2 SELECT numericIndexedVectorToMap(numericIndexedVectorPointwiseMultiply(vec1, vec2)) AS res1, numericIndexedVectorToMap(numericIndexedVectorPointwiseMultiply(vec1, 2)) AS res2;
{"source_file": "numeric-indexed-vector-functions.md"}
[ 0.05649055913090706, -0.017183825373649597, -0.01985965482890606, 0.011492638848721981, 0.008671115152537823, 0.020453613251447678, -0.03855707868933678, -0.035461895167827606, -0.048190049827098846, -0.020696885883808136, -0.06267017871141434, -0.10200362652540207, 0.024992341175675392, -...
b34c5c04-76c3-445f-9b4e-da8913d04f66
response title=Response ┌─res1──────────┬─res2─────────────┐ │ {2:200,3:600} │ {1:20,2:40,3:60} │ └───────────────┴──────────────────┘ numericIndexedVectorPointwiseNotEqual {#numericIndexedVectorPointwiseNotEqual} Introduced in: v25.7 Performs pointwise comparison between a numericIndexedVector and either another numericIndexedVector or a numeric constant. The result is a numericIndexedVector containing the indices where the values are not equal, with all corresponding values set to 1. Syntax sql numericIndexedVectorPointwiseNotEqual(v1, v2) Arguments v1 — numericIndexedVector v2 — A numeric constant or numericIndexedVector object. (U)Int* or Float* or numericIndexedVector Returned value Returns a new numericIndexedVector object. numericIndexedVector Examples Usage example sql title=Query with numericIndexedVectorBuild(mapFromArrays([1, 2, 3], arrayMap(x -> toFloat64(x), [10, 20, 30]))) as vec1, numericIndexedVectorBuild(mapFromArrays([2, 3, 4], arrayMap(x -> toFloat64(x), [20, 20, 30]))) as vec2 SELECT numericIndexedVectorToMap(numericIndexedVectorPointwiseNotEqual(vec1, vec2)) AS res1, numericIndexedVectorToMap(numericIndexedVectorPointwiseNotEqual(vec1, 20)) AS res2; response title=Response ┌─res1──────────┬─res2──────┐ │ {1:1,3:1,4:1} │ {1:1,3:1} │ └───────────────┴───────────┘ numericIndexedVectorPointwiseSubtract {#numericIndexedVectorPointwiseSubtract} Introduced in: v25.7 Performs pointwise subtraction between a numericIndexedVector and either another numericIndexedVector or a numeric constant. Syntax sql numericIndexedVectorPointwiseSubtract(v1, v2) Arguments v1 — numericIndexedVector v2 — A numeric constant or numericIndexedVector object. (U)Int* or Float* or numericIndexedVector Returned value Returns a new numericIndexedVector object. numericIndexedVector Examples Usage example sql title=Query WITH numericIndexedVectorBuild(mapFromArrays([1, 2, 3], arrayMap(x -> toInt32(x), [10, 20, 30]))) AS vec1, numericIndexedVectorBuild(mapFromArrays([2, 3, 4], arrayMap(x -> toInt32(x), [10, 20, 30]))) AS vec2 SELECT numericIndexedVectorToMap(numericIndexedVectorPointwiseSubtract(vec1, vec2)) AS res1, numericIndexedVectorToMap(numericIndexedVectorPointwiseSubtract(vec1, 2)) AS res2; response title=Response ┌─res1───────────────────┬─res2────────────┐ │ {1:10,2:10,3:10,4:-30} │ {1:8,2:18,3:28} │ └────────────────────────┴─────────────────┘ numericIndexedVectorShortDebugString {#numericIndexedVectorShortDebugString} Introduced in: v25.7 Returns internal information of the numericIndexedVector in JSON format. This function is primarily used for debugging purposes. Syntax sql numericIndexedVectorShortDebugString(v) Arguments v — numericIndexedVector Returned value Returns a JSON string containing debug information. String Examples Usage example
{"source_file": "numeric-indexed-vector-functions.md"}
[ 0.050993017852306366, 0.015966501086950302, -0.051564715802669525, -0.010393735021352768, -0.008992196060717106, -0.015631485730409622, -0.00846389215439558, -0.02959948219358921, -0.08074721693992615, -0.02473660372197628, -0.05903773754835129, -0.09518618881702423, 0.10077735036611557, -...
881cea7f-1e96-4ff5-8062-660e27694b73
sql numericIndexedVectorShortDebugString(v) Arguments v — numericIndexedVector Returned value Returns a JSON string containing debug information. String Examples Usage example sql title=Query SELECT numericIndexedVectorShortDebugString(numericIndexedVectorBuild(mapFromArrays([1, 2, 3], [10, 20, 30]))) AS res\G; response title=Response Row 1: ────── res: {"vector_type":"BSI","index_type":"char8_t","value_type":"char8_t","integer_bit_num":8,"fraction_bit_num":0,"zero_indexes_info":{"cardinality":"0"},"non_zero_indexes_info":{"total_cardinality":"3","all_value_sum":60,"number_of_bitmaps":"8","bitmap_info":{"cardinality":{"0":"0","1":"2","2":"2","3":"2","4":"2","5":"0","6":"0","7":"0"}}}} numericIndexedVectorToMap {#numericIndexedVectorToMap} Introduced in: v25.7 Converts a numericIndexedVector to a map. Syntax sql numericIndexedVectorToMap(v) Arguments v — numericIndexedVector Returned value Returns a map with index-value pairs. Map Examples Usage example sql title=Query SELECT numericIndexedVectorToMap(numericIndexedVectorBuild(mapFromArrays([1, 2, 3], [10, 20, 30]))) AS res; response title=Response ┌─res──────────────┐ │ {1:10,2:20,3:30} │ └──────────────────┘
{"source_file": "numeric-indexed-vector-functions.md"}
[ 0.029519731178879738, 0.10063294321298599, -0.018969472497701645, 0.04867735505104065, -0.024682004004716873, -0.01768559403717518, -0.006163048557937145, 0.04787370562553406, -0.02080383710563183, -0.01737026497721672, -0.06263177841901779, -0.10666719824075699, -0.02094680815935135, -0.0...
5f93830d-19db-4241-bd84-0bd3ff91b60b
description: 'Documentation for Natural Language Processing (NLP) functions' sidebar_label: 'NLP' slug: /sql-reference/functions/nlp-functions title: 'Natural Language Processing (NLP) Functions' doc_type: 'reference' keywords: ['NLP', 'Natural Language Processing'] import ExperimentalBadge from '@theme/badges/ExperimentalBadge'; import CloudNotSupportedBadge from '@theme/badges/CloudNotSupportedBadge'; Natural Language Processing (NLP) functions :::warning This is an experimental feature that is currently in development and is not ready for general use. It will change in unpredictable backwards-incompatible ways in future releases. Set allow_experimental_nlp_functions = 1 to enable it. ::: detectCharset {#detectCharset} Introduced in: v22.2 Detects the character set of a non-UTF8-encoded input string. Syntax sql detectCharset(s) Arguments s — The text to analyze. String Returned value Returns a string containing the code of the detected character set String Examples Basic usage sql title=Query SELECT detectCharset('Ich bleibe für ein paar Tage.') response title=Response WINDOWS-1252 detectLanguage {#detectLanguage} Introduced in: v22.2 Detects the language of the UTF8-encoded input string. The function uses the CLD2 library for detection and returns the 2-letter ISO language code. The longer the input, the more precise the language detection will be. Syntax sql detectLanguage(s) Arguments text_to_be_analyzed — The text to analyze. String Returned value Returns the 2-letter ISO code of the detected language. Other possible results: un = unknown, can not detect any language, other = the detected language does not have 2 letter code. String Examples Mixed language text sql title=Query SELECT detectLanguage('Je pense que je ne parviendrai jamais à parler français comme un natif. Where there\'s a will, there\'s a way.') response title=Response fr detectLanguageMixed {#detectLanguageMixed} Introduced in: v22.2 Similar to the detectLanguage function, but detectLanguageMixed returns a Map of 2-letter language codes that are mapped to the percentage of the certain language in the text. Syntax sql detectLanguageMixed(s) Arguments s — The text to analyze String Returned value Returns a map with keys which are 2-letter ISO codes and corresponding values which are a percentage of the text found for that language Map(String, Float32) Examples Mixed languages sql title=Query SELECT detectLanguageMixed('二兎を追う者は一兎をも得ず二兎を追う者は一兎をも得ず A vaincre sans peril, on triomphe sans gloire.') response title=Response {'ja':0.62,'fr':0.36} detectLanguageUnknown {#detectLanguageUnknown} Introduced in: v22.2 Similar to the detectLanguage function, except the detectLanguageUnknown function works with non-UTF8-encoded strings. Prefer this version when your character set is UTF-16 or UTF-32. Syntax sql detectLanguageUnknown('s') Arguments
{"source_file": "nlp-functions.md"}
[ -0.011314909905195236, -0.027935180813074112, 0.05885309725999832, 0.03795626014471054, 0.014651289209723473, 0.03878600895404816, 0.09485919028520584, -0.03394467383623123, -0.016363002359867096, 0.022092880681157112, 0.013699045404791832, -0.06187720596790314, 0.063459113240242, -0.04132...
ff9a5129-a01c-4b3c-911d-0a00dac9b192
Syntax sql detectLanguageUnknown('s') Arguments s — The text to analyze. String Returned value Returns the 2-letter ISO code of the detected language. Other possible results: un = unknown, can not detect any language, other = the detected language does not have 2 letter code. String Examples Basic usage sql title=Query SELECT detectLanguageUnknown('Ich bleibe für ein paar Tage.') response title=Response de detectProgrammingLanguage {#detectProgrammingLanguage} Introduced in: v22.2 Determines the programming language from a given source code snippet. Syntax sql detectProgrammingLanguage('source_code') Arguments source_code — String representation of the source code to analyze. String Returned value Returns programming language String Examples C++ code detection sql title=Query SELECT detectProgrammingLanguage('#include <iostream>') response title=Response C++ detectTonality {#detectTonality} Introduced in: v22.2 Determines the sentiment of the provided text data. :::note Limitation This function is limited in its current form in that it makes use of the embedded emotional dictionary and only works for the Russian language. ::: Syntax sql detectTonality(s) Arguments s — The text to be analyzed. String Returned value Returns the average sentiment value of the words in text Float32 Examples Russian sentiment analysis sql title=Query SELECT detectTonality('Шарик - хороший пёс'), detectTonality('Шарик - пёс'), detectTonality('Шарик - плохой пёс') response title=Response 0.44445, 0, -0.3 lemmatize {#lemmatize} Introduced in: v21.9 Performs lemmatization on a given word. This function needs dictionaries to operate, which can be obtained from github . For more details on loading a dictionary from a local file see page "Defining Dictionaries" . Syntax sql lemmatize(lang, word) Arguments lang — Language which rules will be applied. String word — Lowercase word that needs to be lemmatized. String Returned value Returns the lemmatized form of the word String Examples English lemmatization sql title=Query SELECT lemmatize('en', 'wolves') response title=Response wolf stem {#stem} Introduced in: v21.9 Performs stemming on a given word. Syntax sql stem(lang, word) Arguments lang — Language which rules will be applied. Use the two letter ISO 639-1 code. String word — Lowercase word that needs to be stemmed. String Returned value Returns the stemmed form of the word String Examples English stemming sql title=Query SELECT arrayMap(x -> stem('en', x), ['I', 'think', 'it', 'is', 'a', 'blessing', 'in', 'disguise']) AS res response title=Response ['I','think','it','is','a','bless','in','disguis'] synonyms {#synonyms} Introduced in: v21.9 Finds synonyms of a given word. There are two types of synonym extensions: - plain - wordnet
{"source_file": "nlp-functions.md"}
[ -0.04286213219165802, -0.01956617645919323, -0.011794990859925747, 0.01807829551398754, 0.0023932834155857563, 0.005203811917454004, 0.11896936595439911, 0.005347880069166422, -0.03272587060928345, -0.06259233504533768, 0.020777763798832893, -0.09910299628973007, 0.05967504903674126, -0.04...
7df7e318-d50d-4fdc-b617-d5ec8257fc10
synonyms {#synonyms} Introduced in: v21.9 Finds synonyms of a given word. There are two types of synonym extensions: - plain - wordnet With the plain extension type you need to provide a path to a simple text file, where each line corresponds to a certain synonym set. Words in this line must be separated with space or tab characters. With the wordnet extension type you need to provide a path to a directory with the WordNet thesaurus in it. The thesaurus must contain a WordNet sense index. Syntax sql synonyms(ext_name, word) Arguments ext_name — Name of the extension in which search will be performed. String word — Word that will be searched in extension. String Returned value Returns array of synonyms for the given word. Array(String) Examples Find synonyms sql title=Query SELECT synonyms('list', 'important') response title=Response ['important','big','critical','crucial']
{"source_file": "nlp-functions.md"}
[ -0.005235372111201286, -0.03522494435310364, -0.030598286539316177, 0.002656766213476658, -0.025194182991981506, -0.011854834854602814, 0.07374060899019241, 0.12470286339521408, -0.07124441117048264, 0.0405908077955246, 0.0800328329205513, 0.051655568182468414, 0.05679315701127052, 0.04565...
4d7f50a7-2e22-45de-a6b5-f8fb486b0b2a
description: 'Documentation for Conditional Functions' sidebar_label: 'Conditional' slug: /sql-reference/functions/conditional-functions title: 'Conditional Functions' doc_type: 'reference' Conditional functions Overview {#overview} Using Conditional Results Directly {#using-conditional-results-directly} Conditionals always result to 0 , 1 or NULL . So you can use conditional results directly like this: ```sql SELECT left < right AS is_small FROM LEFT_RIGHT ┌─is_small─┐ │ ᴺᵁᴸᴸ │ │ 1 │ │ 0 │ │ 0 │ │ ᴺᵁᴸᴸ │ └──────────┘ ``` NULL Values in Conditionals {#null-values-in-conditionals} When NULL values are involved in conditionals, the result will also be NULL . ```sql SELECT NULL < 1, 2 < NULL, NULL < NULL, NULL = NULL ┌─less(NULL, 1)─┬─less(2, NULL)─┬─less(NULL, NULL)─┬─equals(NULL, NULL)─┐ │ ᴺᵁᴸᴸ │ ᴺᵁᴸᴸ │ ᴺᵁᴸᴸ │ ᴺᵁᴸᴸ │ └───────────────┴───────────────┴──────────────────┴────────────────────┘ ``` So you should construct your queries carefully if the types are Nullable . The following example demonstrates this by failing to add equals condition to multiIf . ```sql SELECT left, right, multiIf(left < right, 'left is smaller', left > right, 'right is smaller', 'Both equal') AS faulty_result FROM LEFT_RIGHT ┌─left─┬─right─┬─faulty_result────┐ │ ᴺᵁᴸᴸ │ 4 │ Both equal │ │ 1 │ 3 │ left is smaller │ │ 2 │ 2 │ Both equal │ │ 3 │ 1 │ right is smaller │ │ 4 │ ᴺᵁᴸᴸ │ Both equal │ └──────┴───────┴──────────────────┘ ``` CASE statement {#case-statement} The CASE expression in ClickHouse provides conditional logic similar to the SQL CASE operator. It evaluates conditions and returns values based on the first matching condition. ClickHouse supports two forms of CASE: CASE WHEN ... THEN ... ELSE ... END This form allows full flexibility and is internally implemented using the multiIf function. Each condition is evaluated independently, and expressions can include non-constant values. ```sql SELECT number, CASE WHEN number % 2 = 0 THEN number + 1 WHEN number % 2 = 1 THEN number * 10 ELSE number END AS result FROM system.numbers WHERE number < 5; -- is translated to SELECT number, multiIf((number % 2) = 0, number + 1, (number % 2) = 1, number * 10, number) AS result FROM system.numbers WHERE number < 5 ┌─number─┬─result─┐ │ 0 │ 1 │ │ 1 │ 10 │ │ 2 │ 3 │ │ 3 │ 30 │ │ 4 │ 5 │ └────────┴────────┘ 5 rows in set. Elapsed: 0.002 sec. ``` CASE <expr> WHEN <val1> THEN ... WHEN <val2> THEN ... ELSE ... END This more compact form is optimized for constant value matching and internally uses caseWithExpression() . For example, the following is valid:
{"source_file": "conditional-functions.md"}
[ 0.03453054279088974, -0.012991080060601234, 0.055303748697042465, 0.03513219580054283, 0.005435512401163578, 0.0773727297782898, 0.006319316569715738, 0.04526320844888687, -0.0911170020699501, 0.01052776351571083, 0.057600025087594986, -0.10678569972515106, -0.0025747925974428654, -0.03242...
724860e4-9106-4997-b99f-543eed3d1507
This more compact form is optimized for constant value matching and internally uses caseWithExpression() . For example, the following is valid: ```sql SELECT number, CASE number WHEN 0 THEN 100 WHEN 1 THEN 200 ELSE 0 END AS result FROM system.numbers WHERE number < 3; -- is translated to SELECT number, caseWithExpression(number, 0, 100, 1, 200, 0) AS result FROM system.numbers WHERE number < 3 ┌─number─┬─result─┐ │ 0 │ 100 │ │ 1 │ 200 │ │ 2 │ 0 │ └────────┴────────┘ 3 rows in set. Elapsed: 0.002 sec. ``` This form also does not require return expressions to be constants. ```sql SELECT number, CASE number WHEN 0 THEN number + 1 WHEN 1 THEN number * 10 ELSE number END FROM system.numbers WHERE number < 3; -- is translated to SELECT number, caseWithExpression(number, 0, number + 1, 1, number * 10, number) FROM system.numbers WHERE number < 3 ┌─number─┬─caseWithExpr⋯0), number)─┐ │ 0 │ 1 │ │ 1 │ 10 │ │ 2 │ 2 │ └────────┴──────────────────────────┘ 3 rows in set. Elapsed: 0.001 sec. ``` Caveats {#caveats} ClickHouse determines the result type of a CASE expression (or its internal equivalent, such as multiIf ) before evaluating any conditions. This is important when the return expressions differ in type, such as different timezones or numeric types. The result type is selected based on the largest compatible type among all branches. Once this type is selected, all other branches are implicitly cast to it - even if their logic would never be executed at runtime. For types like DateTime64, where the timezone is part of the type signature, this can lead to surprising behavior: the first encountered timezone may be used for all branches, even when other branches specify different timezones. For example, below all rows return the timestamp in the timezone of the first matched branch i.e. Asia/Kolkata ```sql SELECT number, CASE WHEN number = 0 THEN fromUnixTimestamp64Milli(0, 'Asia/Kolkata') WHEN number = 1 THEN fromUnixTimestamp64Milli(0, 'America/Los_Angeles') ELSE fromUnixTimestamp64Milli(0, 'UTC') END AS tz FROM system.numbers WHERE number < 3; -- is translated to SELECT number, multiIf(number = 0, fromUnixTimestamp64Milli(0, 'Asia/Kolkata'), number = 1, fromUnixTimestamp64Milli(0, 'America/Los_Angeles'), fromUnixTimestamp64Milli(0, 'UTC')) AS tz FROM system.numbers WHERE number < 3 ┌─number─┬──────────────────────tz─┐ │ 0 │ 1970-01-01 05:30:00.000 │ │ 1 │ 1970-01-01 05:30:00.000 │ │ 2 │ 1970-01-01 05:30:00.000 │ └────────┴─────────────────────────┘ 3 rows in set. Elapsed: 0.011 sec. ```
{"source_file": "conditional-functions.md"}
[ -0.03734871745109558, 0.027497049421072006, -0.010828295722603798, -0.015389776788651943, -0.10330391675233841, 0.0108686164021492, 0.07217933982610703, 0.03080405294895172, -0.03812584653496742, -0.013607106171548367, -0.0020883374381810427, -0.01669441908597946, 0.0872175469994545, -0.01...
d8c199db-b9b0-46d0-9f66-4fab4aca00aa
3 rows in set. Elapsed: 0.011 sec. ``` Here, ClickHouse sees multiple DateTime64(3, <timezone>) return types. It infers the common type as DateTime64(3, 'Asia/Kolkata' as the first one it sees, implicitly casting other branches to this type. This can be addressed by converting to a string to preserve intended timezone formatting: ```sql SELECT number, multiIf( number = 0, formatDateTime(fromUnixTimestamp64Milli(0), '%F %T', 'Asia/Kolkata'), number = 1, formatDateTime(fromUnixTimestamp64Milli(0), '%F %T', 'America/Los_Angeles'), formatDateTime(fromUnixTimestamp64Milli(0), '%F %T', 'UTC') ) AS tz FROM system.numbers WHERE number < 3; -- is translated to SELECT number, multiIf(number = 0, formatDateTime(fromUnixTimestamp64Milli(0), '%F %T', 'Asia/Kolkata'), number = 1, formatDateTime(fromUnixTimestamp64Milli(0), '%F %T', 'America/Los_Angeles'), formatDateTime(fromUnixTimestamp64Milli(0), '%F %T', 'UTC')) AS tz FROM system.numbers WHERE number < 3 ┌─number─┬─tz──────────────────┐ │ 0 │ 1970-01-01 05:30:00 │ │ 1 │ 1969-12-31 16:00:00 │ │ 2 │ 1970-01-01 00:00:00 │ └────────┴─────────────────────┘ 3 rows in set. Elapsed: 0.002 sec. ``` clamp {#clamp} Introduced in: v24.5 Restricts a value to be within the specified minimum and maximum bounds. If the value is less than the minimum, returns the minimum. If the value is greater than the maximum, returns the maximum. Otherwise, returns the value itself. All arguments must be of comparable types. The result type is the largest compatible type among all arguments. Syntax sql clamp(value, min, max) Arguments value — The value to clamp. - min — The minimum bound. - max — The maximum bound. Returned value Returns the value, restricted to the [min, max] range. Examples Basic usage sql title=Query SELECT clamp(5, 1, 10) AS result; response title=Response ┌─result─┐ │ 5 │ └────────┘ Value below minimum sql title=Query SELECT clamp(-3, 0, 7) AS result; response title=Response ┌─result─┐ │ 0 │ └────────┘ Value above maximum sql title=Query SELECT clamp(15, 0, 7) AS result; response title=Response ┌─result─┐ │ 7 │ └────────┘ greatest {#greatest} Introduced in: v1.1 Returns the greatest value among the arguments. NULL arguments are ignored. For arrays, returns the lexicographically greatest array. For DateTime types, the result type is promoted to the largest type (e.g., DateTime64 if mixed with DateTime32 ). :::note Use setting least_greatest_legacy_null_behavior to change NULL behavior Version 24.12 introduced a backwards-incompatible change such that NULL values are ignored, while previously it returned NULL if one of the arguments was NULL . To retain the previous behavior, set setting least_greatest_legacy_null_behavior (default: false ) to true . ::: Syntax sql greatest(x1[, x2, ...]) Arguments
{"source_file": "conditional-functions.md"}
[ 0.12762632966041565, -0.033839281648397446, -0.03504594415426254, 0.020853858441114426, -0.036593109369277954, 0.03447908163070679, 0.053083308041095734, 0.004199998918920755, -0.0003554995928425342, -0.011968354694545269, 0.012178243137896061, -0.15455548465251923, -0.012664127163589, 0.0...
3ebedfae-00bc-46e2-8ed4-2a611444a174
Syntax sql greatest(x1[, x2, ...]) Arguments x1[, x2, ...] — One or multiple values to compare. All arguments must be of comparable types. Any Returned value Returns the greatest value among the arguments, promoted to the largest compatible type. Any Examples Numeric types sql title=Query SELECT greatest(1, 2, toUInt8(3), 3.) AS result, toTypeName(result) AS type; -- The type returned is a Float64 as the UInt8 must be promoted to 64 bit for the comparison. response title=Response ┌─result─┬─type────┐ │ 3 │ Float64 │ └────────┴─────────┘ Arrays sql title=Query SELECT greatest(['hello'], ['there'], ['world']); response title=Response ┌─greatest(['hello'], ['there'], ['world'])─┐ │ ['world'] │ └───────────────────────────────────────────┘ DateTime types sql title=Query SELECT greatest(toDateTime32(now() + toIntervalDay(1)), toDateTime64(now(), 3)); -- The type returned is a DateTime64 as the DateTime32 must be promoted to 64 bit for the comparison. response title=Response ┌─greatest(toD⋯(now(), 3))─┐ │ 2025-05-28 15:50:53.000 │ └──────────────────────────┘ if {#if} Introduced in: v1.1 Performs conditional branching. If the condition cond evaluates to a non-zero value, the function returns the result of the expression then . If cond evaluates to zero or NULL, the result of the else expression is returned. The setting short_circuit_function_evaluation controls whether short-circuit evaluation is used. If enabled, the then expression is evaluated only on rows where cond is true and the else expression where cond is false. For example, with short-circuit evaluation, no division-by-zero exception is thrown when executing the following query: sql SELECT if(number = 0, 0, intDiv(42, number)) FROM numbers(10) then and else must be of a similar type. Syntax sql if(cond, then, else) Arguments cond — The evaluated condition. UInt8 or Nullable(UInt8) or NULL then — The expression returned if cond is true. - else — The expression returned if cond is false or NULL . Returned value The result of either the then or else expressions, depending on condition cond . Examples Example usage sql title=Query SELECT if(1, 2 + 2, 2 + 6) AS res; response title=Response ┌─res─┐ │ 4 │ └─────┘ least {#least} Introduced in: v1.1 Returns the smallest value among the arguments. NULL arguments are ignored. For arrays, returns the lexicographically least array. For DateTime types, the result type is promoted to the largest type (e.g., DateTime64 if mixed with DateTime32).
{"source_file": "conditional-functions.md"}
[ 0.06726883351802826, 0.02639547362923622, -0.0008174678077921271, -0.021901734173297882, -0.08568544685840607, -0.08456350117921829, 0.029828151687979698, 0.04890423268079758, -0.05390002578496933, -0.02122151292860508, -0.0729338601231575, -0.025444258004426956, 0.014304201118648052, 0.01...
16c2c609-2382-484e-beb9-af8efc3f4f2b
For arrays, returns the lexicographically least array. For DateTime types, the result type is promoted to the largest type (e.g., DateTime64 if mixed with DateTime32). :::note Use setting least_greatest_legacy_null_behavior to change NULL behavior Version 24.12 introduced a backwards-incompatible change such that NULL values are ignored, while previously it returned NULL if one of the arguments was NULL . To retain the previous behavior, set setting least_greatest_legacy_null_behavior (default: false ) to true . ::: Syntax sql least(x1[, x2, ...]) Arguments x1[, x2, ...] — A single value or multiple values to compare. All arguments must be of comparable types. Any Returned value Returns the least value among the arguments, promoted to the largest compatible type. Any Examples Numeric types sql title=Query SELECT least(1, 2, toUInt8(3), 3.) AS result, toTypeName(result) AS type; -- The type returned is a Float64 as the UInt8 must be promoted to 64 bit for the comparison. response title=Response ┌─result─┬─type────┐ │ 1 │ Float64 │ └────────┴─────────┘ Arrays sql title=Query SELECT least(['hello'], ['there'], ['world']); response title=Response ┌─least(['hell⋯ ['world'])─┐ │ ['hello'] │ └──────────────────────────┘ DateTime types sql title=Query SELECT least(toDateTime32(now() + toIntervalDay(1)), toDateTime64(now(), 3)); -- The type returned is a DateTime64 as the DateTime32 must be promoted to 64 bit for the comparison. response title=Response ┌─least(toDate⋯(now(), 3))─┐ │ 2025-05-27 15:55:20.000 │ └──────────────────────────┘ multiIf {#multiIf} Introduced in: v1.1 Allows writing the CASE operator more compactly in the query. Evaluates each condition in order. For the first condition that is true (non-zero and not NULL ), returns the corresponding branch value. If none of the conditions are true, returns the else value. Setting short_circuit_function_evaluation controls whether short-circuit evaluation is used. If enabled, the then_i expression is evaluated only on rows where ((NOT cond_1) AND ... AND (NOT cond_{i-1}) AND cond_i) is true. For example, with short-circuit evaluation, no division-by-zero exception is thrown when executing the following query: sql SELECT multiIf(number = 2, intDiv(1, number), number = 5) FROM numbers(10) All branch and else expressions must have a common supertype. NULL conditions are treated as false. Syntax sql multiIf(cond_1, then_1, cond_2, then_2, ..., else) Aliases : caseWithoutExpression , caseWithoutExpr Arguments cond_N — The N-th evaluated condition which controls if then_N is returned. UInt8 or Nullable(UInt8) or NULL then_N — The result of the function when cond_N is true. - else — The result of the function if none of the conditions is true. Returned value Returns the result of then_N for matching cond_N , otherwise returns the else condition.
{"source_file": "conditional-functions.md"}
[ 0.06348534673452377, 0.023432407528162003, -0.000027156842406839132, 0.0009909120853990316, -0.035254836082458496, -0.010100061073899269, 0.02439616620540619, 0.040627025067806244, -0.06122242286801338, -0.013286181725561619, -0.0689210444688797, -0.02836986631155014, 0.004074150696396828, ...
20f23c66-8e01-45be-af3c-f5bda7c89210
Returned value Returns the result of then_N for matching cond_N , otherwise returns the else condition. Examples Example usage ```sql title=Query CREATE TABLE LEFT_RIGHT (left Nullable(UInt8), right Nullable(UInt8)) ENGINE = Memory; INSERT INTO LEFT_RIGHT VALUES (NULL, 4), (1, 3), (2, 2), (3, 1), (4, NULL); SELECT left, right, multiIf(left < right, 'left is smaller', left > right, 'left is greater', left = right, 'Both equal', 'Null value') AS result FROM LEFT_RIGHT; ``` response title=Response ┌─left─┬─right─┬─result──────────┐ │ ᴺᵁᴸᴸ │ 4 │ Null value │ │ 1 │ 3 │ left is smaller │ │ 2 │ 2 │ Both equal │ │ 3 │ 1 │ left is greater │ │ 4 │ ᴺᵁᴸᴸ │ Null value │ └──────┴───────┴─────────────────┘
{"source_file": "conditional-functions.md"}
[ -0.07034844905138016, 0.02934250794351101, -0.01065723318606615, 0.015256703831255436, -0.08585214614868164, 0.0018217936158180237, 0.0011149849742650986, 0.022881081327795982, -0.0341084823012352, -0.011272480711340904, 0.025522157549858093, 0.006524659227579832, 0.002494445536285639, -0....
4e61a9d9-19b1-4500-be75-deabbd8d2385
description: 'Documentation for functions for working with nullable values' sidebar_label: 'Nullable' slug: /sql-reference/functions/functions-for-nulls title: 'Functions for working with nullable values' keywords: ['nullable', 'functions'] doc_type: 'reference' Functions for working with nullable values assumeNotNull {#assumeNotNull} Introduced in: v1.1 Returns the corresponding non- Nullable value for a value of type Nullable . If the original value is NULL , an arbitrary result can be returned. See also: functions ifNull and coalesce . Syntax sql assumeNotNull(x) Arguments x — The original value of any nullable type. Nullable(T) Returned value Returns the non-nullable value, if the original value was not NULL , otherwise an arbitrary value, if the input value is NULL . Any Examples Usage example ```sql title=Query CREATE TABLE t_null (x Int8, y Nullable(Int8)) ENGINE=MergeTree() ORDER BY x; INSERT INTO t_null VALUES (1, NULL), (2, 3); SELECT assumeNotNull(y) FROM table; SELECT toTypeName(assumeNotNull(y)) FROM t_null; ``` response title=Response ┌─assumeNotNull(y)─┐ │ 0 │ │ 3 │ └──────────────────┘ ┌─toTypeName(assumeNotNull(y))─┐ │ Int8 │ │ Int8 │ └──────────────────────────────┘ coalesce {#coalesce} Introduced in: v1.1 Returns the leftmost non- NULL argument. Syntax sql coalesce(x[, y, ...]) Arguments x[, y, ...] — Any number of parameters of non-compound type. All parameters must be of mutually compatible data types. Any Returned value Returns the first non- NULL argument, otherwise NULL , if all arguments are NULL . Any or NULL Examples Usage example ```sql title=Query -- Consider a list of contacts that may specify multiple ways to contact a customer. CREATE TABLE aBook ( name String, mail Nullable(String), phone Nullable(String), telegram Nullable(UInt32) ) ENGINE = MergeTree ORDER BY tuple(); INSERT INTO aBook VALUES ('client 1', NULL, '123-45-67', 123), ('client 2', NULL, NULL, NULL); -- The mail and phone fields are of type String, but the telegram field is UInt32 so it needs to be converted to String. -- Get the first available contact method for the customer from the contact list SELECT name, coalesce(mail, phone, CAST(telegram,'Nullable(String)')) FROM aBook; ``` response title=Response ┌─name─────┬─coalesce(mail, phone, CAST(telegram, 'Nullable(String)'))─┐ │ client 1 │ 123-45-67 │ │ client 2 │ ᴺᵁᴸᴸ │ └──────────┴───────────────────────────────────────────────────────────┘ firstNonDefault {#firstNonDefault} Introduced in: v25.9 Returns the first non-default value from a set of arguments Syntax ```sql ``` Arguments
{"source_file": "functions-for-nulls.md"}
[ -0.03859792649745941, 0.027560735121369362, -0.06635617464780807, 0.02209010161459446, -0.04758519306778908, 0.006308153737336397, 0.04732101783156395, 0.05069887638092041, -0.09446977823972702, -0.0018956762505695224, 0.06046821549534798, -0.05944880470633507, 0.02495948225259781, -0.0717...
f74110fe-0830-4c2d-b4a7-efc5a3c8e52a
firstNonDefault {#firstNonDefault} Introduced in: v25.9 Returns the first non-default value from a set of arguments Syntax ```sql ``` Arguments arg1 — The first argument to check - arg2 — The second argument to check - ... — Additional arguments to check Returned value Result type is the supertype of all arguments Examples integers sql title=Query SELECT firstNonDefault(0, 1, 2) response title=Response 1 strings sql title=Query SELECT firstNonDefault('', 'hello', 'world') response title=Response 'hello' nulls sql title=Query SELECT firstNonDefault(NULL, 0 :: UInt8, 1 :: UInt8) response title=Response 1 nullable zero sql title=Query SELECT firstNonDefault(NULL, 0 :: Nullable(UInt8), 1 :: Nullable(UInt8)) response title=Response 0 ifNull {#ifNull} Introduced in: v1.1 Returns an alternative value if the first argument is NULL . Syntax sql ifNull(x, alt) Arguments x — The value to check for NULL . Any alt — The value that the function returns if x is NULL . Any Returned value Returns the value of x if it is not NULL , otherwise alt . Any Examples Usage example sql title=Query SELECT ifNull('a', 'b'), ifNull(NULL, 'b'); response title=Response ┌─ifNull('a', 'b')─┬─ifNull(NULL, 'b')─┐ │ a │ b │ └──────────────────┴───────────────────┘ isNotDistinctFrom {#isNotDistinctFrom} Introduced in: v23.8 Performs a null-safe comparison between two JOIN keys. This function will consider two NULL values as identical and will return true , which is distinct from the usual equals behavior where comparing two NULL values would return NULL . :::info This function is an internal function used by the implementation of JOIN ON . Please do not use it manually in queries. ::: For a complete example see: NULL values in JOIN keys . Syntax sql isNotDistinctFrom(x, y) Arguments x — First JOIN key to compare. Any y — Second JOIN key to compare. Any Returned value Returns true when x and y are both NULL , otherwise false . Bool Examples isNotNull {#isNotNull} Introduced in: v1.1 Checks if the argument is not NULL . Also see: operator IS NOT NULL . Syntax sql isNotNull(x) Arguments x — A value of non-compound data type. Any Returned value Returns 1 if x is not NULL , otherwise 0 . UInt8 Examples Usage example ```sql title=Query CREATE TABLE t_null ( x Int32, y Nullable(Int32) ) ENGINE = MergeTree ORDER BY tuple(); INSERT INTO t_null VALUES (1, NULL), (2, 3); SELECT x FROM t_null WHERE isNotNull(y); ``` response title=Response ┌─x─┐ │ 2 │ └───┘ isNull {#isNull} Introduced in: v1.1 Checks if the argument is NULL . Also see: operator IS NULL . Syntax sql isNull(x) Arguments x — A value of non-compound data type. Any Returned value Returns 1 if x is NULL , otherwise 0 . UInt8 Examples Usage example
{"source_file": "functions-for-nulls.md"}
[ -0.015902195125818253, -0.031097957864403725, -0.01807808317244053, 0.055587880313396454, -0.06924067437648773, -0.039024192839860916, 0.08824136108160019, -0.014892194420099258, -0.05219288542866707, -0.004480086732655764, 0.041733432561159134, -0.08550351113080978, 0.015630044043064117, ...
a1f35d22-6c39-438d-955c-83d5f3059a84
Syntax sql isNull(x) Arguments x — A value of non-compound data type. Any Returned value Returns 1 if x is NULL , otherwise 0 . UInt8 Examples Usage example ```sql title=Query CREATE TABLE t_null ( x Int32, y Nullable(Int32) ) ENGINE = MergeTree ORDER BY tuple(); INSERT INTO t_null VALUES (1, NULL), (2, 3); SELECT x FROM t_null WHERE isNull(y); ``` response title=Response ┌─x─┐ │ 1 │ └───┘ isNullable {#isNullable} Introduced in: v22.7 Checks whether the argument's data type is Nullable (i.e it allows NULL values). Syntax sql isNullable(x) Arguments x — A value of any data type. Any Returned value Returns 1 if x is of a Nullable data type, otherwise 0 . UInt8 Examples Usage example sql title=Query CREATE TABLE tab ( ordinary_col UInt32, nullable_col Nullable(UInt32) ) ENGINE = MergeTree ORDER BY tuple(); INSERT INTO tab (ordinary_col, nullable_col) VALUES (1,1), (2, 2), (3,3); SELECT isNullable(ordinary_col), isNullable(nullable_col) FROM tab; response title=Response ┌───isNullable(ordinary_col)──┬───isNullable(nullable_col)──┐ │ 0 │ 1 │ │ 0 │ 1 │ │ 0 │ 1 │ └─────────────────────────────┴─────────────────────────────┘ isZeroOrNull {#isZeroOrNull} Introduced in: v20.3 Checks if the argument is either zero ( 0 ) or NULL . Syntax sql isZeroOrNull(x) Arguments x — A numeric value. UInt Returned value Returns 1 if x is NULL or equal to zero, otherwise 0 . UInt8/16/32/64 or Float32/Float64 Examples Usage example ```sql title=Query CREATE TABLE t_null ( x Int32, y Nullable(Int32) ) ENGINE = MergeTree ORDER BY tuple(); INSERT INTO t_null VALUES (1, NULL), (2, 0), (3, 3); SELECT x FROM t_null WHERE isZeroOrNull(y); ``` response title=Response ┌─x─┐ │ 1 │ │ 2 │ └───┘ nullIf {#nullIf} Introduced in: v1.1 Returns NULL if both arguments are equal. Syntax sql nullIf(x, y) Arguments x — The first value. Any y — The second value. Any Returned value Returns NULL if both arguments are equal, otherwise returns the first argument. NULL or Nullable(x) Examples Usage example sql title=Query SELECT nullIf(1, 1), nullIf(1, 2); response title=Response ┌─nullIf(1, 1)─┬─nullIf(1, 2)─┐ │ ᴺᵁᴸᴸ │ 1 │ └──────────────┴──────────────┘ toNullable {#toNullable} Introduced in: v1.1 Converts the provided argument type to Nullable . Syntax sql toNullable(x) Arguments x — A value of any non-compound type. Any Returned value Returns the input value but of Nullable type. Nullable(Any) Examples Usage example sql title=Query SELECT toTypeName(10), toTypeName(toNullable(10));
{"source_file": "functions-for-nulls.md"}
[ 0.04932737722992897, 0.01146972831338644, -0.060962971299886703, 0.011785796843469143, -0.05702394247055054, -0.03303424268960953, 0.046201057732105255, 0.03790103271603584, -0.07172621041536331, 0.02870001830160618, 0.049432430416345596, -0.05641314014792442, 0.0025833449326455593, -0.021...
e5cdbd51-e570-4117-a445-9ea045a1d2bf
Returned value Returns the input value but of Nullable type. Nullable(Any) Examples Usage example sql title=Query SELECT toTypeName(10), toTypeName(toNullable(10)); response title=Response ┌─toTypeName(10)─┬─toTypeName(toNullable(10))─┐ │ UInt8 │ Nullable(UInt8) │ └────────────────┴────────────────────────────┘
{"source_file": "functions-for-nulls.md"}
[ -0.02333511784672737, -0.000745575875043869, -0.04882160946726799, 0.06945830583572388, -0.11139173805713654, 0.030831117182970047, 0.03369729965925217, 0.05905386433005333, -0.07293006777763367, -0.06152813509106636, 0.028250308707356453, -0.046025313436985016, 0.02407110296189785, -0.006...
7ddcbcbd-904d-446d-acf9-87453e4835bb
description: 'Documentation for Bit Functions' sidebar_label: 'Bit' slug: /sql-reference/functions/bit-functions title: 'Bit Functions' doc_type: 'reference' Bit functions Bit functions work for any pair of types from UInt8 , UInt16 , UInt32 , UInt64 , Int8 , Int16 , Int32 , Int64 , Float32 , or Float64 . Some functions support String and FixedString types. The result type is an integer with bits equal to the maximum bits of its arguments. If at least one of the arguments is signed, the result is a signed number. If an argument is a floating-point number, it is cast to Int64. bitAnd {#bitAnd} Introduced in: v1.1 Performs bitwise AND operation between two values. Syntax sql bitAnd(a, b) Arguments a — First value. (U)Int* or Float* b — Second value. (U)Int* or Float* Returned value Returns the result of bitwise operation a AND b Examples Usage example ``sql title=Query CREATE TABLE bits ( a UInt8, b` UInt8 ) ENGINE = Memory; INSERT INTO bits VALUES (0, 0), (0, 1), (1, 0), (1, 1); SELECT a, b, bitAnd(a, b) FROM bits ``` response title=Response ┌─a─┬─b─┬─bitAnd(a, b)─┐ │ 0 │ 0 │ 0 │ │ 0 │ 1 │ 0 │ │ 1 │ 0 │ 0 │ │ 1 │ 1 │ 1 │ └───┴───┴──────────────┘ bitCount {#bitCount} Introduced in: v20.3 Calculates the number of bits set to one in the binary representation of a number. Syntax sql bitCount(x) Arguments x — An integer or float value. (U)Int* or Float* Returned value Returns the number of bits set to one in x . UInt8 . :::note The function does not convert the input value to a larger type ( sign extension ). For example: bitCount(toUInt8(-1)) = 8 . ::: Examples Usage example sql title=Query SELECT bin(333), bitCount(333); response title=Response ┌─bin(333)─────────┬─bitCount(333)─┐ │ 0000000101001101 │ 5 │ └──────────────────┴───────────────┘ bitHammingDistance {#bitHammingDistance} Introduced in: v21.1 Returns the Hamming Distance between the bit representations of two numbers. Can be used with SimHash functions for detection of semi-duplicate strings. The smaller the distance, the more similar the strings are. Syntax sql bitHammingDistance(x, y) Arguments x — First number for Hamming distance calculation. (U)Int* or Float* y — Second number for Hamming distance calculation. (U)Int* or Float* Returned value Returns the hamming distance between x and y UInt8 Examples Usage example sql title=Query SELECT bitHammingDistance(111, 121); response title=Response ┌─bitHammingDistance(111, 121)─┐ │ 3 │ └──────────────────────────────┘ bitNot {#bitNot} Introduced in: v1.1 Performs the bitwise NOT operation. Syntax sql bitNot(a) Arguments a — Value for which to apply bitwise NOT operation. (U)Int* or Float* or String Returned value
{"source_file": "bit-functions.md"}
[ 0.03221527487039566, 0.02911103144288063, -0.08677846193313599, 0.0030082790181040764, -0.08929069340229034, -0.06282173097133636, 0.07957008481025696, 0.035601627081632614, -0.07297898828983307, -0.03307230770587921, -0.034367069602012634, -0.040369413793087006, 0.04205317795276642, -0.05...
2dcaee4b-fb3a-48b4-aaa8-89da95f385a6
Performs the bitwise NOT operation. Syntax sql bitNot(a) Arguments a — Value for which to apply bitwise NOT operation. (U)Int* or Float* or String Returned value Returns the result of ~a i.e a with bits flipped. Examples Usage example sql title=Query SELECT CAST('5', 'UInt8') AS original, bin(original) AS original_binary, bitNot(original) AS result, bin(bitNot(original)) AS result_binary; response title=Response ┌─original─┬─original_binary─┬─result─┬─result_binary─┐ │ 5 │ 00000101 │ 250 │ 11111010 │ └──────────┴─────────────────┴────────┴───────────────┘ bitOr {#bitOr} Introduced in: v1.1 Performs bitwise OR operation between two values. Syntax sql bitOr(a, b) Arguments a — First value. (U)Int* or Float* b — Second value. (U)Int* or Float* Returned value Returns the result of bitwise operation a OR b Examples Usage example ``sql title=Query CREATE TABLE bits ( a UInt8, b` UInt8 ) ENGINE = Memory; INSERT INTO bits VALUES (0, 0), (0, 1), (1, 0), (1, 1); SELECT a, b, bitOr(a, b) FROM bits; ``` response title=Response ┌─a─┬─b─┬─bitOr(a, b)─┐ │ 0 │ 0 │ 0 │ │ 0 │ 1 │ 1 │ │ 1 │ 0 │ 1 │ │ 1 │ 1 │ 1 │ └───┴───┴─────────────┘ bitRotateLeft {#bitRotateLeft} Introduced in: v1.1 Rotate bits left by a certain number of positions. Bits that fall off wrap around to the right. Syntax sql bitRotateLeft(a, N) Arguments a — A value to rotate. (U)Int8/16/32/64 N — The number of positions to rotate left. UInt8/16/32/64 Returned value Returns the rotated value with type equal to that of a . (U)Int8/16/32/64 Examples Usage example sql title=Query SELECT 99 AS a, bin(a), bitRotateLeft(a, 2) AS a_rotated, bin(a_rotated); response title=Response ┌──a─┬─bin(a)───┬─a_rotated─┬─bin(a_rotated)─┐ │ 99 │ 01100011 │ 141 │ 10001101 │ └────┴──────────┴───────────┴────────────────┘ bitRotateRight {#bitRotateRight} Introduced in: v1.1 Rotate bits right by a certain number of positions. Bits that fall off wrap around to the left. Syntax sql bitRotateRight(a, N) Arguments a — A value to rotate. (U)Int8/16/32/64 N — The number of positions to rotate right. UInt8/16/32/64 Returned value Returns the rotated value with type equal to that of a . (U)Int8/16/32/64 Examples Usage example sql title=Query SELECT 99 AS a, bin(a), bitRotateRight(a, 2) AS a_rotated, bin(a_rotated); response title=Response ┌──a─┬─bin(a)───┬─a_rotated─┬─bin(a_rotated)─┐ │ 99 │ 01100011 │ 216 │ 11011000 │ └────┴──────────┴───────────┴────────────────┘ bitShiftLeft {#bitShiftLeft} Introduced in: v1.1 Shifts the binary representation of a value to the left by a specified number of bit positions. A FixedString or a String is treated as a single multibyte value.
{"source_file": "bit-functions.md"}
[ 0.04242540895938873, 0.019181538373231888, -0.08053770661354065, 0.03687891736626625, -0.09534520655870438, -0.12132560461759567, 0.06587280333042145, -0.031245222315192223, -0.017743993550539017, 0.006144004873931408, -0.019984912127256393, -0.05087393894791603, 0.05871713533997536, -0.04...
0abe682c-ad4f-4d44-affd-0bcad8365776
Introduced in: v1.1 Shifts the binary representation of a value to the left by a specified number of bit positions. A FixedString or a String is treated as a single multibyte value. Bits of a FixedString value are lost as they are shifted out. On the contrary, a String value is extended with additional bytes, so no bits are lost. Syntax sql bitShiftLeft(a, N) Arguments a — A value to shift. (U)Int* or String or FixedString N — The number of positions to shift. UInt8/16/32/64 Returned value Returns the shifted value with type equal to that of a . Examples Usage example with binary encoding sql title=Query SELECT 99 AS a, bin(a), bitShiftLeft(a, 2) AS a_shifted, bin(a_shifted); response title=Response ┌──a─┬─bin(99)──┬─a_shifted─┬─bin(bitShiftLeft(99, 2))─┐ │ 99 │ 01100011 │ 140 │ 10001100 │ └────┴──────────┴───────────┴──────────────────────────┘ Usage example with hexadecimal encoding sql title=Query SELECT 'abc' AS a, hex(a), bitShiftLeft(a, 4) AS a_shifted, hex(a_shifted); response title=Response ┌─a───┬─hex('abc')─┬─a_shifted─┬─hex(bitShiftLeft('abc', 4))─┐ │ abc │ 616263 │ &0 │ 06162630 │ └─────┴────────────┴───────────┴─────────────────────────────┘ Usage example with Fixed String encoding sql title=Query SELECT toFixedString('abc', 3) AS a, hex(a), bitShiftLeft(a, 4) AS a_shifted, hex(a_shifted); response title=Response ┌─a───┬─hex(toFixedString('abc', 3))─┬─a_shifted─┬─hex(bitShiftLeft(toFixedString('abc', 3), 4))─┐ │ abc │ 616263 │ &0 │ 162630 │ └─────┴──────────────────────────────┴───────────┴───────────────────────────────────────────────┘ bitShiftRight {#bitShiftRight} Introduced in: v1.1 Shifts the binary representation of a value to the right by a specified number of bit positions. A FixedString or a String is treated as a single multibyte value. Bits of a FixedString value are lost as they are shifted out. On the contrary, a String value is extended with additional bytes, so no bits are lost. Syntax sql bitShiftRight(a, N) Arguments a — A value to shift. (U)Int* or String or FixedString N — The number of positions to shift. UInt8/16/32/64 Returned value Returns the shifted value with type equal to that of a . Examples Usage example with binary encoding sql title=Query SELECT 101 AS a, bin(a), bitShiftRight(a, 2) AS a_shifted, bin(a_shifted); response title=Response ┌───a─┬─bin(101)─┬─a_shifted─┬─bin(bitShiftRight(101, 2))─┐ │ 101 │ 01100101 │ 25 │ 00011001 │ └─────┴──────────┴───────────┴────────────────────────────┘ Usage example with hexadecimal encoding sql title=Query SELECT 'abc' AS a, hex(a), bitShiftLeft(a, 4) AS a_shifted, hex(a_shifted);
{"source_file": "bit-functions.md"}
[ 0.011500322259962559, -0.012458245269954205, -0.04593680053949356, 0.04163215309381485, -0.07400137931108475, -0.0029737562872469425, 0.04874948412179947, -0.00046044826740399003, 0.007759269792586565, 0.0014426879351958632, -0.043940722942352295, -0.03989245370030403, 0.03381888568401337, ...
e4c0f130-04f9-4f58-9cb0-b834726c795b
Usage example with hexadecimal encoding sql title=Query SELECT 'abc' AS a, hex(a), bitShiftLeft(a, 4) AS a_shifted, hex(a_shifted); response title=Response ┌─a───┬─hex('abc')─┬─a_shifted─┬─hex(bitShiftRight('abc', 12))─┐ │ abc │ 616263 │ │ 0616 │ └─────┴────────────┴───────────┴───────────────────────────────┘ Usage example with Fixed String encoding sql title=Query SELECT toFixedString('abc', 3) AS a, hex(a), bitShiftRight(a, 12) AS a_shifted, hex(a_shifted); response title=Response ┌─a───┬─hex(toFixedString('abc', 3))─┬─a_shifted─┬─hex(bitShiftRight(toFixedString('abc', 3), 12))─┐ │ abc │ 616263 │ │ 000616 │ └─────┴──────────────────────────────┴───────────┴─────────────────────────────────────────────────┘ bitSlice {#bitSlice} Introduced in: v22.2 Returns a substring starting with the bit from the 'offset' index that is 'length' bits long. Syntax sql bitSlice(s, offset[, length]) Arguments s — The String or Fixed String to slice. String or FixedString offset — Returns the starting bit position (1-based indexing). Positive values: count from the beginning of the string. Negative values: count from the end of the string. [`(U)Int8/16/32/64`](/sql-reference/data-types/int-uint) or [`Float*`](/sql-reference/data-types/float) length — Optional. The number of bits to extract. Positive values: extract length bits. Negative values: extract from the offset to (string_length - |length|) . Omitted: extract from offset to end of string. If length is not a multiple of 8, the result is padded with zeros on the right. (U)Int8/16/32/64 or Float* Returned value Returns a string containing the extracted bits, represented as a binary sequence. The result is always padded to byte boundaries (multiples of 8 bits) String Examples Usage example sql title=Query SELECT bin('Hello'), bin(bitSlice('Hello', 1, 8)); SELECT bin('Hello'), bin(bitSlice('Hello', 1, 2)); SELECT bin('Hello'), bin(bitSlice('Hello', 1, 9)); SELECT bin('Hello'), bin(bitSlice('Hello', -4, 8));
{"source_file": "bit-functions.md"}
[ 0.03335357457399368, 0.017039237543940544, -0.03923393785953522, 0.008756106719374657, -0.10125237703323364, 0.02743753418326378, 0.028213227167725563, 0.020950257778167725, -0.020082684233784676, -0.014093591831624508, 0.0024540452286601067, -0.029805295169353485, 0.058426059782505035, -0...
5f317dba-a3e6-4fff-a3ba-7e36d1ba019a
response title=Response ┌─bin('Hello')─────────────────────────────┬─bin(bitSlice('Hello', 1, 8))─┐ │ 0100100001100101011011000110110001101111 │ 01001000 │ └──────────────────────────────────────────┴──────────────────────────────┘ ┌─bin('Hello')─────────────────────────────┬─bin(bitSlice('Hello', 1, 2))─┐ │ 0100100001100101011011000110110001101111 │ 01000000 │ └──────────────────────────────────────────┴──────────────────────────────┘ ┌─bin('Hello')─────────────────────────────┬─bin(bitSlice('Hello', 1, 9))─┐ │ 0100100001100101011011000110110001101111 │ 0100100000000000 │ └──────────────────────────────────────────┴──────────────────────────────┘ ┌─bin('Hello')─────────────────────────────┬─bin(bitSlice('Hello', -4, 8))─┐ │ 0100100001100101011011000110110001101111 │ 11110000 │ └──────────────────────────────────────────┴───────────────────────────────┘ bitTest {#bitTest} Introduced in: v1.1 Takes any number and converts it into binary form , then returns the value of the bit at a specified position. Counting is done right-to-left, starting at 0. Syntax sql bitTest(a, i) Arguments a — Number to convert. (U)Int8/16/32/64 or Float* i — Position of the bit to return. (U)Int8/16/32/64 or Float* Returned value Returns the value of the bit at position i in the binary representation of a UInt8 Examples Usage example sql title=Query SELECT bin(2), bitTest(2, 1); response title=Response ┌─bin(2)───┬─bitTest(2, 1)─┐ │ 00000010 │ 1 │ └──────────┴───────────────┘ bitTestAll {#bitTestAll} Introduced in: v1.1 Returns result of the logical conjunction (AND operator) of all bits at the given positions. Counts right-to-left, starting at 0. The logical AND between two bits is true if and only if both input bits are true. Syntax sql bitTestAll(a, index1[, index2, ... , indexN]) Arguments a — An integer value. (U)Int8/16/32/64 index1, ... — One or multiple positions of bits. (U)Int8/16/32/64 Returned value Returns the result of the logical conjunction UInt8 Examples Usage example 1 sql title=Query SELECT bitTestAll(43, 0, 1, 3, 5); response title=Response ┌─bin(43)──┬─bitTestAll(43, 0, 1, 3, 5)─┐ │ 00101011 │ 1 │ └──────────┴────────────────────────────┘ Usage example 2 sql title=Query SELECT bitTestAll(43, 0, 1, 3, 5, 2); response title=Response ┌─bin(43)──┬─bitTestAll(4⋯1, 3, 5, 2)─┐ │ 00101011 │ 0 │ └──────────┴──────────────────────────┘ bitTestAny {#bitTestAny} Introduced in: v1.1 Returns result of the logical disjunction (OR operator) of all bits at the given positions in a number. Counts right-to-left, starting at 0. The logical OR between two bits is true if at least one of the input bits is true. Syntax sql bitTestAny(a, index1[, index2, ... , indexN]) Arguments a — An integer value. (U)Int8/16/32/64
{"source_file": "bit-functions.md"}
[ 0.02059859223663807, 0.036838073283433914, -0.024190708994865417, 0.05762835964560509, -0.0665772333741188, -0.07061325013637543, 0.06060433015227318, -0.021839763969182968, -0.07058783620595932, 0.007363581098616123, 0.005563643295317888, -0.05866186320781708, 0.05493917688727379, -0.0232...
6707edac-36f5-4a86-8e45-b7c94886d198
Syntax sql bitTestAny(a, index1[, index2, ... , indexN]) Arguments a — An integer value. (U)Int8/16/32/64 index1, ... — One or multiple positions of bits. (U)Int8/16/32/64 Returned value Returns the result of the logical disjunction UInt8 Examples Usage example 1 sql title=Query SELECT bitTestAny(43, 0, 2); response title=Response ┌─bin(43)──┬─bitTestAny(43, 0, 2)─┐ │ 00101011 │ 1 │ └──────────┴──────────────────────┘ Usage example 2 sql title=Query SELECT bitTestAny(43, 4, 2); response title=Response ┌─bin(43)──┬─bitTestAny(43, 4, 2)─┐ │ 00101011 │ 0 │ └──────────┴──────────────────────┘ bitXor {#bitXor} Introduced in: v1.1 Performs bitwise exclusive or (XOR) operation between two values. Syntax sql bitXor(a, b) Arguments a — First value. (U)Int* or Float* b — Second value. (U)Int* or Float* Returned value Returns the result of bitwise operation a XOR b Examples Usage example ``sql title=Query CREATE TABLE bits ( a UInt8, b` UInt8 ) ENGINE = Memory; INSERT INTO bits VALUES (0, 0), (0, 1), (1, 0), (1, 1); SELECT a, b, bitXor(a, b) FROM bits; ``` response title=Response ┌─a─┬─b─┬─bitXor(a, b)─┐ │ 0 │ 0 │ 0 │ │ 0 │ 1 │ 1 │ │ 1 │ 0 │ 1 │ │ 1 │ 1 │ 0 │ └───┴───┴──────────────┘
{"source_file": "bit-functions.md"}
[ 0.02238363027572632, 0.049372557550668716, -0.042026832699775696, 0.03655083104968071, -0.06107255071401596, -0.07306032627820969, 0.058692075312137604, -0.04557294026017189, -0.0450938381254673, -0.025484653189778328, -0.014583345502614975, -0.10014823824167252, 0.06097930669784546, -0.00...
97c875d9-6d16-4da0-993c-a4cec0f76667
description: 'Documentation for time window functions' sidebar_label: 'Time window' slug: /sql-reference/functions/time-window-functions title: 'Time window functions' doc_type: 'reference' keywords: ['time window'] import ExperimentalBadge from '@theme/badges/ExperimentalBadge'; import CloudNotSupportedBadge from '@theme/badges/CloudNotSupportedBadge'; Time window functions Time window functions return the inclusive lower and exclusive upper bound of the corresponding window. The functions for working with WindowView are listed below: hop {#hop} Introduced in: v21.12 A hopping time window has a fixed duration ( window_interval ) and hops by a specified hop interval ( hop_interval ). If the hop_interval is smaller than the window_interval , hopping windows are overlapping. Thus, records can be assigned to multiple windows. Since one record can be assigned to multiple hop windows, the function only returns the bound of the first window when hop function is used without WINDOW VIEW. Syntax sql hop(time_attr, hop_interval, window_interval[, timezone]) Arguments time_attr — Date and time. DateTime hop_interval — Positive Hop interval. Interval window_interval — Positive Window interval. Interval timezone — Optional. Timezone name. String Returned value Returns the inclusive lower and exclusive upper bound of the corresponding hopping window. Tuple(DateTime, DateTime) Examples Hopping window sql title=Query SELECT hop(now(), INTERVAL '1' DAY, INTERVAL '2' DAY) response title=Response ('2024-07-03 00:00:00','2024-07-05 00:00:00') hopEnd {#hopEnd} Introduced in: v22.1 Returns the exclusive upper bound of the corresponding hopping window. Since one record can be assigned to multiple hop windows, the function only returns the bound of the first window when hop function is used without WINDOW VIEW . Syntax sql hopEnd(time_attr, hop_interval, window_interval[, timezone]) Arguments time_attr — Date and time. DateTime hop_interval — Positive Hop interval. Interval window_interval — Positive Window interval. Interval timezone — Optional. Timezone name. String Returned value Returns the exclusive upper bound of the corresponding hopping window. DateTime Examples Hopping window end sql title=Query SELECT hopEnd(now(), INTERVAL '1' DAY, INTERVAL '2' DAY) response title=Response 2024-07-05 00:00:00 hopStart {#hopStart} Introduced in: v22.1 Returns the inclusive lower bound of the corresponding hopping window. Since one record can be assigned to multiple hop windows, the function only returns the bound of the first window when hop function is used without WINDOW VIEW . Syntax sql hopStart(time_attr, hop_interval, window_interval[, timezone]) Arguments time_attr — Date and time. DateTime hop_interval — Positive Hop interval. Interval window_interval — Positive Window interval. Interval
{"source_file": "time-window-functions.md"}
[ -0.02408846653997898, 0.022820258513092995, -0.02720414102077484, -0.02353777177631855, -0.04825888201594353, 0.0203782357275486, 0.07255370169878006, -0.02147797867655754, 0.016989706084132195, -0.03367217630147934, -0.018564527854323387, -0.02226264774799347, 0.004570879507809877, -0.023...
40cd307d-3a25-4251-b1ec-08aa01e85389
Arguments time_attr — Date and time. DateTime hop_interval — Positive Hop interval. Interval window_interval — Positive Window interval. Interval timezone — Optional. Timezone name. String Returned value Returns the inclusive lower bound of the corresponding hopping window. DateTime Examples Hopping window start sql title=Query SELECT hopStart(now(), INTERVAL '1' DAY, INTERVAL '2' DAY) response title=Response 2024-07-03 00:00:00 tumble {#tumble} Introduced in: v21.12 A tumbling time window assigns records to non-overlapping, continuous windows with a fixed duration ( interval ). Syntax sql tumble(time_attr, interval[, timezone]) Arguments time_attr — Date and time. DateTime interval — Window interval in Interval. Interval timezone — Optional. Timezone name. String Returned value Returns the inclusive lower and exclusive upper bound of the corresponding tumbling window. Tuple(DateTime, DateTime) Examples Tumbling window sql title=Query SELECT tumble(now(), toIntervalDay('1')) response title=Response ('2024-07-04 00:00:00','2024-07-05 00:00:00') tumbleEnd {#tumbleEnd} Introduced in: v22.1 Returns the exclusive upper bound of the corresponding tumbling window. Syntax sql tumbleEnd(time_attr, interval[, timezone]) Arguments time_attr — Date and time. DateTime interval — Window interval in Interval. Interval timezone — Optional. Timezone name. String Returned value Returns the exclusive upper bound of the corresponding tumbling window. DateTime Examples Tumbling window end sql title=Query SELECT tumbleEnd(now(), toIntervalDay('1')) response title=Response 2024-07-05 00:00:00 tumbleStart {#tumbleStart} Introduced in: v22.1 Returns the inclusive lower bound of the corresponding tumbling window. Syntax sql tumbleStart(time_attr, interval[, timezone]) Arguments time_attr — Date and time. DateTime interval — Window interval in Interval. Interval timezone — Optional. Timezone name. String Returned value Returns the inclusive lower bound of the corresponding tumbling window. DateTime Examples Tumbling window start sql title=Query SELECT tumbleStart(now(), toIntervalDay('1')) response title=Response 2024-07-04 00:00:00 Related content {#related-content} Time-series use-case guides
{"source_file": "time-window-functions.md"}
[ -0.025868024677038193, 0.024273419752717018, -0.00735407555475831, 0.026711182668805122, -0.046115532517433167, -0.08023350685834885, 0.035733312368392944, 0.016077574342489243, -0.024315310642123222, -0.039448969066143036, -0.03779367730021477, -0.01754264533519745, -0.026915637776255608, ...
0628fa5b-6138-4b07-ae29-2d002ef2b276
description: 'Documentation for functions used for working with IPv4 and IPv6 addresses.' sidebar_label: 'IP Addresses' slug: /sql-reference/functions/ip-address-functions title: 'Functions for working with IPv4 and IPv6 addresses' doc_type: 'reference' Functions for working with IPv4 and IPv6 addresses IPv4CIDRToRange {#IPv4CIDRToRange} Introduced in: v20.1 Takes an IPv4 address with its Classless Inter-Domain Routing (CIDR) prefix length and returns the subnet's address range as a tuple of two IPv4 values: the first and last addresses in that subnet. For the IPv6 version see IPv6CIDRToRange . Syntax sql IPv4CIDRToRange(ipv4, cidr) Arguments ipv4 — IPv4 address. IPv4 or String cidr — CIDR value. UInt8 Returned value Returns a tuple with two IPv4 addresses representing the subnet range. Tuple(IPv4, IPv4) Examples Usage example sql title=Query SELECT IPv4CIDRToRange(toIPv4('192.168.5.2'), 16); response title=Response ┌─IPv4CIDRToRange(toIPv4('192.168.5.2'), 16)─┐ │ ('192.168.0.0','192.168.255.255') │ └────────────────────────────────────────────┘ IPv4NumToString {#IPv4NumToString} Introduced in: v1.1 Converts a 32-bit integer to its IPv4 address string representation in dotted decimal notation (A.B.C.D format). Interprets the input using big-endian byte ordering. Syntax sql IPv4NumToString(num) Aliases : INET_NTOA Arguments num — IPv4 address as UInt32 number. UInt32 Returned value Returns a number representing the MAC address, or 0 if the format is invalid. String Examples Usage example sql title=Query IPv4NumToString(3232235521) response title=Response 192.168.0.1 IPv4NumToStringClassC {#IPv4NumToStringClassC} Introduced in: v1.1 Converts a 32-bit integer to its IPv4 address string representation in dotted decimal notation (A.B.C.D format), similar to IPv4NumToString but using xxx instead of the last octet. Syntax sql IPv4NumToStringClassC(num) Arguments num — IPv4 address as UInt32 number. UInt32 Returned value Returns the IPv4 address string with xxx replacing the last octet. String Examples Basic example with aggregation sql title=Query SELECT IPv4NumToStringClassC(ClientIP) AS k, count() AS c FROM test.hits GROUP BY k ORDER BY c DESC LIMIT 10 response title=Response ┌─k──────────────┬─────c─┐ │ 83.149.9.xxx │ 26238 │ │ 217.118.81.xxx │ 26074 │ │ 213.87.129.xxx │ 25481 │ │ 83.149.8.xxx │ 24984 │ │ 217.118.83.xxx │ 22797 │ │ 78.25.120.xxx │ 22354 │ │ 213.87.131.xxx │ 21285 │ │ 78.25.121.xxx │ 20887 │ │ 188.162.65.xxx │ 19694 │ │ 83.149.48.xxx │ 17406 │ └────────────────┴───────┘ IPv4StringToNum {#IPv4StringToNum} Introduced in: v1.1 Converts an IPv4 address string in dotted decimal notation (A.B.C.D format) to its corresponding 32-bit integer representation. (The reverse of IPv4NumToString ). If the IPv4 address has an invalid format, an exception is thrown. Syntax
{"source_file": "ip-address-functions.md"}
[ 0.06518709659576416, -0.05416669324040413, -0.020007725805044174, -0.022224610671401024, -0.04236815497279167, 0.018178796395659447, 0.0005871611065231264, -0.01781851053237915, -0.058887824416160583, -0.06543493270874023, 0.011379730887711048, -0.017989138141274452, 0.003308770013973117, ...
d95cecf0-0dc5-449e-bf2a-2113580b76e3
Syntax sql IPv4StringToNum(string) Aliases : INET_ATON Arguments string — IPv4 address string. String Returned value Returns theIPv4 address. UInt32 Examples Usage example sql title=Query IPv4StringToNum('192.168.0.1') response title=Response 3232235521 IPv4StringToNumOrDefault {#IPv4StringToNumOrDefault} Introduced in: v22.3 Converts an IPv4 address string in dotted decimal notation (A.B.C.D format) to its corresponding 32-bit integer representation but if the IPv4 address has an invalid format, it returns 0 . Syntax sql IPv4StringToNumOrDefault(string) Arguments string — IPv4 address string. String Returned value Returns the IPv4 address, or 0 if invalid. UInt32 Examples Example with an invalid address sql title=Query SELECT IPv4StringToNumOrDefault('127.0.0.1') AS valid, IPv4StringToNumOrDefault('invalid') AS invalid; response title=Response ┌──────valid─┬─invalid─┐ │ 2130706433 │ 0 │ └────────────┴─────────┘ IPv4StringToNumOrNull {#IPv4StringToNumOrNull} Introduced in: v22.3 Converts a 32-bit integer to its IPv4 address string representation in dotted decimal notation (A.B.C.D format) but if the IPv4 address has an invalid format, it returns NULL . Syntax sql IPv4StringToNumOrNull(string) Arguments string — IPv4 address string. String Returned value Returns the IPv4 address, or NULL if invalid. Nullable(UInt32) Examples Example with an invalid address sql title=Query SELECT IPv4StringToNumOrNull('127.0.0.1') AS valid, IPv4StringToNumOrNull('invalid') AS invalid; response title=Response ┌──────valid─┬─invalid─┐ │ 2130706433 │ ᴺᵁᴸᴸ │ └────────────┴─────────┘ IPv4ToIPv6 {#IPv4ToIPv6} Introduced in: v1.1 Interprets a (big endian) 32-bit number as an IPv4 address, which is then interpreted as the corresponding IPv6 address in FixedString(16) format. Syntax sql IPv4ToIPv6(x) Arguments x — IPv4 address. UInt32 Returned value Returns an IPv6 address in binary format. FixedString(16) Examples Usage example sql title=Query SELECT IPv6NumToString(IPv4ToIPv6(IPv4StringToNum('192.168.0.1'))) AS addr; response title=Response ┌─addr───────────────┐ │ ::ffff:192.168.0.1 │ └────────────────────┘ IPv6CIDRToRange {#IPv6CIDRToRange} Introduced in: v20.1 Takes an IPv6 address with its Classless Inter-Domain Routing (CIDR) prefix length and returns the subnet's address range as a tuple of two IPv6 values: the lowest and highest addresses in that subnet. For the IPv4 version see IPv4CIDRToRange . Syntax sql IPv6CIDRToRange(ipv6, cidr) Arguments ipv6 — IPv6 address. IPv6 or String cidr — CIDR value. UInt8 Returned value Returns a tuple with two IPv6 addresses representing the subnet range. Tuple(IPv6, IPv6) Examples Usage example sql title=Query SELECT IPv6CIDRToRange(toIPv6('2001:0db8:0000:85a3:0000:0000:ac1f:8001'), 32);
{"source_file": "ip-address-functions.md"}
[ 0.040924396365880966, -0.012498083524405956, -0.041058748960494995, -0.024787455797195435, -0.09373150020837784, -0.020039400085806847, 0.06124262511730194, 0.009920158423483372, 0.028341712430119514, -0.039541829377412796, -0.04181792959570885, -0.046262476593256, -0.011992107145488262, 0...
c5923e12-cfed-4cb2-a1ea-750e6c752a0b
Examples Usage example sql title=Query SELECT IPv6CIDRToRange(toIPv6('2001:0db8:0000:85a3:0000:0000:ac1f:8001'), 32); response title=Response ┌─IPv6CIDRToRange(toIPv6('2001:0db8:0000:85a3:0000:0000:ac1f:8001'), 32)─┐ │ ('2001:db8::','2001:db8:ffff:ffff:ffff:ffff:ffff:ffff') │ └────────────────────────────────────────────────────────────────────────┘ IPv6NumToString {#IPv6NumToString} Introduced in: v1.1 Converts an IPv6 address from binary format (FixedString(16)) to its standard text representation. IPv4-mapped IPv6 addresses are displayed in the format ::ffff:111.222.33.44 . Syntax sql IPv6NumToString(x) Aliases : INET6_NTOA Arguments x — IPv6 address in binary format. FixedString(16) or IPv6 Returned value Returns the IPv6 address string in text format. String Examples Usage example sql title=Query SELECT IPv6NumToString(toFixedString(unhex('2A0206B8000000000000000000000011'), 16)) AS addr; response title=Response ┌─addr─────────┐ │ 2a02:6b8::11 │ └──────────────┘ IPv6 with hits analysis sql title=Query SELECT IPv6NumToString(ClientIP6 AS k), count() AS c FROM hits_all WHERE EventDate = today() AND substring(ClientIP6, 1, 12) != unhex('00000000000000000000FFFF') GROUP BY k ORDER BY c DESC LIMIT 10 response title=Response ┌─IPv6NumToString(ClientIP6)──────────────┬─────c─┐ │ 2a02:2168:aaa:bbbb::2 │ 24695 │ │ 2a02:2698:abcd:abcd:abcd:abcd:8888:5555 │ 22408 │ │ 2a02:6b8:0:fff::ff │ 16389 │ │ 2a01:4f8:111:6666::2 │ 16016 │ │ 2a02:2168:888:222::1 │ 15896 │ │ 2a01:7e00::ffff:ffff:ffff:222 │ 14774 │ │ 2a02:8109:eee:ee:eeee:eeee:eeee:eeee │ 14443 │ │ 2a02:810b:8888:888:8888:8888:8888:8888 │ 14345 │ │ 2a02:6b8:0:444:4444:4444:4444:4444 │ 14279 │ │ 2a01:7e00::ffff:ffff:ffff:ffff │ 13880 │ └─────────────────────────────────────────┴───────┘ IPv6 mapped IPv4 addresses sql title=Query SELECT IPv6NumToString(ClientIP6 AS k), count() AS c FROM hits_all WHERE EventDate = today() GROUP BY k ORDER BY c DESC LIMIT 10 response title=Response ┌─IPv6NumToString(ClientIP6)─┬──────c─┐ │ ::ffff:94.26.111.111 │ 747440 │ │ ::ffff:37.143.222.4 │ 529483 │ │ ::ffff:5.166.111.99 │ 317707 │ │ ::ffff:46.38.11.77 │ 263086 │ │ ::ffff:79.105.111.111 │ 186611 │ │ ::ffff:93.92.111.88 │ 176773 │ │ ::ffff:84.53.111.33 │ 158709 │ │ ::ffff:217.118.11.22 │ 154004 │ │ ::ffff:217.118.11.33 │ 148449 │ │ ::ffff:217.118.11.44 │ 148243 │ └────────────────────────────┴────────┘ IPv6StringToNum {#IPv6StringToNum} Introduced in: v1.1 Converts an IPv6 address from its standard text representation to binary format ( FixedString(16) ). Accepts IPv4-mapped IPv6 addresses in the format ::ffff:111.222.33.44. . If the IPv6 address has an invalid format, an exception is thrown.
{"source_file": "ip-address-functions.md"}
[ -0.008644076064229012, 0.004705508705228567, -0.011934097856283188, -0.003339693183079362, -0.04030301421880722, 0.021490277722477913, 0.02911178395152092, -0.013198391534388065, 0.03863319009542465, -0.04206918925046921, -0.02141861990094185, -0.032241031527519226, -0.006478064693510532, ...
08ad3cf2-a71c-4ffa-84fb-79c91c62c4d0
If the input string contains a valid IPv4 address, returns its IPv6 equivalent. HEX can be uppercase or lowercase. Syntax sql IPv6StringToNum(string) Aliases : INET6_ATON Arguments string — IPv6 address string. String Returned value Returns theIPv6 address in binary format. FixedString(16) Examples Basic example sql title=Query SELECT addr, cutIPv6(IPv6StringToNum(addr), 0, 0) FROM (SELECT ['notaddress', '127.0.0.1', '1111::ffff'] AS addr) ARRAY JOIN addr; response title=Response ┌─addr───────┬─cutIPv6(IPv6StringToNum(addr), 0, 0)─┐ │ notaddress │ :: │ │ 127.0.0.1 │ ::ffff:127.0.0.1 │ │ 1111::ffff │ 1111::ffff │ └────────────┴──────────────────────────────────────┘ IPv6StringToNumOrDefault {#IPv6StringToNumOrDefault} Introduced in: v22.3 Converts an IPv6 address from its standard text representation to binary format ( FixedString(16) ). Accepts IPv4-mapped IPv6 addresses in the format ::ffff:111.222.33.44. . If the IPv6 address has an invalid format, it returns the default value :: . Syntax sql IPv6StringToNumOrDefault(string) Arguments string — IPv6 address string. String Returned value IPv6 address in binary format, or zero-filled FixedString(16) if invalid. FixedString(16) Examples Basic example with invalid address sql title=Query SELECT IPv6NumToString(IPv6StringToNumOrDefault('2001:db8::1')) AS valid, IPv6NumToString(IPv6StringToNumOrDefault('invalid')) AS invalid; response title=Response ┌─valid───────┬─invalid─┐ │ 2001:db8::1 │ :: │ └─────────────┴─────────┘ IPv6StringToNumOrNull {#IPv6StringToNumOrNull} Introduced in: v22.3 Converts an IPv6 address from its standard text representation to binary format ( FixedString(16) ). Accepts IPv4-mapped IPv6 addresses in the format ::ffff:111.222.33.44. . If the IPv6 address has an invalid format, it returns NULL . Syntax sql IPv6StringToNumOrNull(string) Arguments string — IPv6 address string. String Returned value Returns IPv6 address in binary format, or NULL if invalid. Nullable(FixedString(16)) Examples Basic example with invalid address sql title=Query SELECT IPv6NumToString(IPv6StringToNumOrNull('2001:db8::1')) AS valid, IPv6StringToNumOrNull('invalid') AS invalid; response title=Response ┌─valid───────┬─invalid─┐ │ 2001:db8::1 │ ᴺᵁᴸᴸ │ └─────────────┴─────────┘ cutIPv6 {#cutIPv6} Introduced in: v1.1 Accepts a FixedString(16) value containing the IPv6 address in binary format. Returns a string containing the address of the specified number of bytes removed in text format. Syntax sql cutIPv6(x, bytesToCutForIPv6, bytesToCutForIPv4) Arguments x — IPv6 address in binary format. FixedString(16) or IPv6 bytesToCutForIPv6 — Number of bytes to cut for IPv6. UInt8 bytesToCutForIPv4 — Number of bytes to cut for IPv4. UInt8 Returned value
{"source_file": "ip-address-functions.md"}
[ 0.03896128758788109, 0.00408557103946805, -0.01762966997921467, -0.026688819751143456, -0.06762994080781937, 0.006265461910516024, 0.02711007371544838, -0.04890298470854759, -0.006455389782786369, -0.05499137192964554, -0.014665430411696434, -0.023895204067230225, -0.028918571770191193, -0...
34d64239-3614-418c-a359-07bb809be991
bytesToCutForIPv6 — Number of bytes to cut for IPv6. UInt8 bytesToCutForIPv4 — Number of bytes to cut for IPv4. UInt8 Returned value Returns a string containing the IPv6 address in text format with specified bytes removed. String Examples Usage example sql title=Query WITH IPv6StringToNum('2001:0DB8:AC10:FE01:FEED:BABE:CAFE:F00D') AS ipv6, IPv4ToIPv6(IPv4StringToNum('192.168.0.1')) AS ipv4 SELECT cutIPv6(ipv6, 2, 0), cutIPv6(ipv4, 0, 2) response title=Response ┌─cutIPv6(ipv6, 2, 0)─────────────────┬─cutIPv6(ipv4, 0, 2)─┐ │ 2001:db8:ac10:fe01:feed:babe:cafe:0 │ ::ffff:192.168.0.0 │ └─────────────────────────────────────┴─────────────────────┘ isIPAddressInRange {#isIPAddressInRange} Introduced in: v21.4 Determines if an IP address is contained in a network represented in the Classless Inter-Domain Routing (CIDR) notation. This function accepts both IPv4 and IPv6 addresses (and networks) represented as strings. It returns 0 if the IP version of the address and the CIDR don't match. Syntax sql isIPAddressInRange(address, prefix) Arguments address — An IPv4 or IPv6 address. String prefix — An IPv4 or IPv6 network prefix in CIDR. String Returned value Returns 1 if the IP version of the address and the CIDR match, otherwise 0 . UInt8 Examples IPv4 address in range sql title=Query SELECT isIPAddressInRange('127.0.0.1', '127.0.0.0/8') response title=Response 1 IPv4 address not in range sql title=Query SELECT isIPAddressInRange('127.0.0.1', 'ffff::/16') response title=Response 0 IPv6 address not in range sql title=Query SELECT isIPAddressInRange('::ffff:192.168.0.1', '::ffff:192.168.0.4/128') response title=Response 0 isIPv4String {#isIPv4String} Introduced in: v21.1 Determines whether the input string is an IPv4 address or not. For the IPv6 version see isIPv6String . Syntax sql isIPv4String(string) Arguments string — IP address string to check. String Returned value Returns 1 if string is IPv4 address, otherwise 0 . UInt8 Examples Usage example sql title=Query SELECT addr, isIPv4String(addr) FROM( SELECT ['0.0.0.0', '127.0.0.1', '::ffff:127.0.0.1'] AS addr ) ARRAY JOIN addr; response title=Response ┌─addr─────────────┬─isIPv4String(addr)─┐ │ 0.0.0.0 │ 1 │ │ 127.0.0.1 │ 1 │ │ ::ffff:127.0.0.1 │ 0 │ └──────────────────┴────────────────────┘ isIPv6String {#isIPv6String} Introduced in: v21.1 Determines whether the input string is an IPv6 address or not. For the IPv4 version see isIPv4String . Syntax sql isIPv6String(string) Arguments string — IP address string to check. String Returned value Returns 1 if string is IPv6 address, otherwise 0 . UInt8 Examples Usage example sql title=Query SELECT addr, isIPv6String(addr) FROM(SELECT ['::', '1111::ffff', '::ffff:127.0.0.1', '127.0.0.1'] AS addr) ARRAY JOIN addr;
{"source_file": "ip-address-functions.md"}
[ 0.04993906989693642, 0.01001122035086155, 0.0180901437997818, 0.009877682663500309, -0.02535552717745304, 0.027257846668362617, 0.041541147977113724, -0.08755557984113693, 0.03397322818636894, -0.037954241037368774, -0.0015736425993964076, -0.03742910921573639, -0.039907973259687424, -0.09...
53416d63-1953-4771-8b99-fd9fc9fb7ea7
Examples Usage example sql title=Query SELECT addr, isIPv6String(addr) FROM(SELECT ['::', '1111::ffff', '::ffff:127.0.0.1', '127.0.0.1'] AS addr) ARRAY JOIN addr; response title=Response ┌─addr─────────────┬─isIPv6String(addr)─┐ │ :: │ 1 │ │ 1111::ffff │ 1 │ │ ::ffff:127.0.0.1 │ 1 │ │ 127.0.0.1 │ 0 │ └──────────────────┴────────────────────┘ toIPv4 {#toIPv4} Introduced in: v20.1 Converts a string or a UInt32 form of IPv4 address to type IPv4. It is similar to IPv4StringToNum and IPv4NumToString functions but it supports both string and unsigned integer data types as input arguments. Syntax sql toIPv4(x) Arguments x — An IPv4 address String or UInt8/16/32 Returned value Returns an IPv4 address. IPv4 Examples Usage example sql title=Query SELECT toIPv4('171.225.130.45'); response title=Response ┌─toIPv4('171.225.130.45')─┐ │ 171.225.130.45 │ └──────────────────────────┘ Comparison with IPv4StringToNum and IPv4NumToString functions. sql title=Query WITH '171.225.130.45' AS IPv4_string SELECT hex(IPv4StringToNum(IPv4_string)), hex(toIPv4(IPv4_string)) response title=Response ┌─hex(IPv4StringToNum(IPv4_string))─┬─hex(toIPv4(IPv4_string))─┐ │ ABE1822D │ ABE1822D │ └───────────────────────────────────┴──────────────────────────┘ Conversion from an integer sql title=Query SELECT toIPv4(2130706433); response title=Response ┌─toIPv4(2130706433)─┐ │ 127.0.0.1 │ └────────────────────┘ toIPv4OrDefault {#toIPv4OrDefault} Introduced in: v22.3 Converts a string or a UInt32 form of an IPv4 address to IPv4 type. If the IPv4 address has an invalid format, it returns 0.0.0.0 (0 IPv4), or the provided IPv4 default. Syntax sql toIPv4OrDefault(string[, default]) Arguments string — IP address string to convert. String default — Optional. The value to return if string is an invalid IPv4 address. IPv4 Returned value Returns a string converted to the current IPv4 address, or the default value if conversion fails. IPv4 Examples Valid and invalid IPv4 strings sql title=Query WITH '192.168.1.1' AS valid_IPv4_string, '999.999.999.999' AS invalid_IPv4_string, 'not_an_ip' AS malformed_string SELECT toIPv4OrDefault(valid_IPv4_string) AS valid, toIPv4OrDefault(invalid_IPv4_string) AS default_value, toIPv4OrDefault(malformed_string, toIPv4('8.8.8.8')) AS provided_default; response title=Response ┌─valid─────────┬─default_value─┬─provided_default─┐ │ 192.168.1.1 │ 0.0.0.0 │ 8.8.8.8 │ └───────────────┴───────────────┴──────────────────┘ toIPv4OrNull {#toIPv4OrNull} Introduced in: v22.3 Converts an input value to a value of type IPv4 but returns NULL in case of an error. Like toIPv4 but returns NULL instead of throwing an exception on conversion errors.
{"source_file": "ip-address-functions.md"}
[ 0.027284855023026466, -0.03637802228331566, -0.027606327086687088, -0.0014199318829923868, -0.05373340845108032, -0.002046903595328331, 0.062090788036584854, -0.009458707645535469, 0.033807314932346344, -0.05620378628373146, -0.03180753067135811, -0.03966959938406944, -0.023012489080429077, ...
a6d09a2b-8ad7-4ea4-9d81-22df0d47fb79
Converts an input value to a value of type IPv4 but returns NULL in case of an error. Like toIPv4 but returns NULL instead of throwing an exception on conversion errors. Supported arguments: - String representations of IPv4 addresses in dotted decimal notation. - Integer representations of IPv4 addresses. Unsupported arguments (return NULL ): - Invalid IP address formats. - IPv6 addresses. - Out-of-range values. - Malformed addresses. Syntax sql toIPv4OrNull(x) Arguments x — A string or integer representation of an IPv4 address. String or Integer Returned value Returns an IPv4 address if successful, otherwise NULL . IPv4 or NULL Examples Usage example sql title=Query SELECT toIPv4OrNull('192.168.1.1') AS valid_ip, toIPv4OrNull('invalid.ip') AS invalid_ip response title=Response ┌─valid_ip────┬─invalid_ip─┐ │ 192.168.1.1 │ ᴺᵁᴸᴸ │ └─────────────┴────────────┘ toIPv4OrZero {#toIPv4OrZero} Introduced in: v23.1 Converts an input value to a value of type IPv4 but returns zero IPv4 address in case of an error. Like toIPv4 but returns zero IPv4 address ( 0.0.0.0 ) instead of throwing an exception on conversion errors. Supported arguments: - String representations of IPv4 addresses in dotted decimal notation. - Integer representations of IPv4 addresses. Unsupported arguments (return zero IPv4): - Invalid IP address formats. - IPv6 addresses. - Out-of-range values. Syntax sql toIPv4OrZero(x) Arguments x — A string or integer representation of an IPv4 address. String or Integer Returned value Returns an IPv4 address if successful, otherwise zero IPv4 address ( 0.0.0.0 ). IPv4 Examples Usage example sql title=Query SELECT toIPv4OrZero('192.168.1.1') AS valid_ip, toIPv4OrZero('invalid.ip') AS invalid_ip response title=Response ┌─valid_ip────┬─invalid_ip─┐ │ 192.168.1.1 │ 0.0.0.0 │ └─────────────┴────────────┘ toIPv6 {#toIPv6} Introduced in: v20.1 onverts a string or a UInt128 form of IPv6 address to IPv6 type. For strings, if the IPv6 address has an invalid format, returns an empty value. Similar to IPv6StringToNum and IPv6NumToString functions, which convert IPv6 address to and from binary format (i.e. FixedString(16) ). If the input string contains a valid IPv4 address, then the IPv6 equivalent of the IPv4 address is returned. Syntax sql toIPv6(x) Arguments x — An IP address. String or UInt128 Returned value Returns an IPv6 address. IPv6 Examples Usage example sql title=Query WITH '2001:438:ffff::407d:1bc1' AS IPv6_string SELECT hex(IPv6StringToNum(IPv6_string)), hex(toIPv6(IPv6_string)); response title=Response ┌─hex(IPv6StringToNum(IPv6_string))─┬─hex(toIPv6(IPv6_string))─────────┐ │ 20010438FFFF000000000000407D1BC1 │ 20010438FFFF000000000000407D1BC1 │ └───────────────────────────────────┴──────────────────────────────────┘ IPv4-to-IPv6 mapping
{"source_file": "ip-address-functions.md"}
[ 0.08832766115665436, -0.00805997010320425, -0.014574713073670864, -0.009532575495541096, -0.05085316300392151, 0.022084413096308708, 0.023292241618037224, -0.055854685604572296, -0.004238664638251066, -0.03547348082065582, -0.04493296518921852, -0.03987331688404083, 0.027720525860786438, -...
3b02c98f-bbe1-42f3-a56a-c5b4ce3382f5
IPv4-to-IPv6 mapping sql title=Query SELECT toIPv6('127.0.0.1'); response title=Response ┌─toIPv6('127.0.0.1')─┐ │ ::ffff:127.0.0.1 │ └─────────────────────┘ toIPv6OrDefault {#toIPv6OrDefault} Introduced in: v22.3 Converts a string or a UInt128 form of IPv6 address to IPv6 type. If the IPv6 address has an invalid format, it returns :: (0 IPv6) or the provided IPv6 default. Syntax sql toIPv6OrDefault(string[, default]) Arguments string — IP address string to convert. - default — Optional. The value to return if string has an invalid format. Returned value Returns the IPv6 address, otherwise :: or the provided optional default if argument string has an invalid format. IPv6 Examples Valid and invalid IPv6 strings sql title=Query WITH '2001:0db8:85a3:0000:0000:8a2e:0370:7334' AS valid_IPv6_string, '2001:0db8:85a3::8a2e:370g:7334' AS invalid_IPv6_string, 'not_an_ipv6' AS malformed_string SELECT toIPv6OrDefault(valid_IPv6_string) AS valid, toIPv6OrDefault(invalid_IPv6_string) AS default_value, toIPv6OrDefault(malformed_string, toIPv6('::1')) AS provided_default; response title=Response ┌─valid──────────────────────────────────┬─default_value─┬─provided_default─┐ │ 2001:db8:85a3::8a2e:370:7334 │ :: │ ::1 │ └────────────────────────────────────────┴───────────────┴──────────────────┘ toIPv6OrNull {#toIPv6OrNull} Introduced in: v22.3 Converts an input value to a value of type IPv6 but returns NULL in case of an error. Like toIPv6 but returns NULL instead of throwing an exception on conversion errors. Supported arguments: - String representations of IPv6 addresses in standard notation. - String representations of IPv4 addresses (converted to IPv4-mapped IPv6). - Binary representations of IPv6 addresses. Unsupported arguments (return NULL ): - Invalid IP address formats. - Malformed IPv6 addresses. - Out-of-range values. - Invalid notation. Syntax sql toIPv6OrNull(x) Arguments x — A string representation of an IPv6 or IPv4 address. String Returned value Returns an IPv6 address if successful, otherwise NULL . IPv6 or NULL Examples Usage example sql title=Query SELECT toIPv6OrNull('2001:0db8:85a3:0000:0000:8a2e:0370:7334') AS valid_ipv6, toIPv6OrNull('invalid::ip') AS invalid_ipv6 response title=Response ┌─valid_ipv6──────────────────────────┬─invalid_ipv6─┐ │ 2001:db8:85a3::8a2e:370:7334 │ ᴺᵁᴸᴸ │ └─────────────────────────────────────┴──────────────┘ toIPv6OrZero {#toIPv6OrZero} Introduced in: v23.1 Converts an input value to a value of type IPv6 but returns zero IPv6 address in case of an error. Like toIPv6 but returns zero IPv6 address ( :: ) instead of throwing an exception on conversion errors.
{"source_file": "ip-address-functions.md"}
[ 0.059634264558553696, -0.04478530213236809, -0.020148128271102905, 0.010898610576987267, -0.09660623222589493, 0.015655500814318657, 0.024427086114883423, -0.04979044571518898, -0.0007271180511452258, -0.040633343160152435, -0.040416330099105835, -0.025086527690291405, -0.03743738681077957, ...
5c40efbc-36b9-4dee-8d1e-4fc1c8a16496
Supported arguments: - String representations of IPv6 addresses in standard notation. - String representations of IPv4 addresses (converted to IPv4-mapped IPv6). - Binary representations of IPv6 addresses. Unsupported arguments (return zero IPv6): - Invalid IP address formats. - Malformed IPv6 addresses. - Out-of-range values. Syntax sql toIPv6OrZero(x) Arguments x — A string representation of an IPv6 or IPv4 address. String Returned value Returns an IPv6 address if successful, otherwise zero IPv6 address ( :: ). IPv6 Examples Usage example sql title=Query SELECT toIPv6OrZero('2001:0db8:85a3:0000:0000:8a2e:0370:7334') AS valid_ipv6, toIPv6OrZero('invalid::ip') AS invalid_ipv6 response title=Response ┌─valid_ipv6──────────────────────────┬─invalid_ipv6─┐ │ 2001:db8:85a3::8a2e:370:7334 │ :: │ └─────────────────────────────────────┴──────────────┘
{"source_file": "ip-address-functions.md"}
[ 0.024205777794122696, -0.0287619661539793, -0.05207686498761177, -0.009984627366065979, -0.07171177119016647, 0.026874030008912086, 0.009569560177624226, -0.08243559300899506, -0.005577229429036379, -0.03577571362257004, -0.026363614946603775, -0.015987414866685867, -0.030549317598342896, ...
2bc3c28f-3eb4-4cf2-9b07-342f8cec4a26
description: 'Documentation for functions for splitting strings' sidebar_label: 'String splitting' slug: /sql-reference/functions/splitting-merging-functions title: 'Functions for splitting strings' doc_type: 'reference' import DeprecatedBadge from '@theme/badges/DeprecatedBadge'; Functions for splitting strings :::note The documentation below is generated from the system.functions system table. ::: alphaTokens {#alphaTokens} Introduced in: v1.1 Selects substrings of consecutive bytes from the ranges a-z and A-Z and returns an array of the selected substrings. Syntax sql alphaTokens(s[, max_substrings]) Aliases : splitByAlpha Arguments s — The string to split. String max_substrings — Optional. When max_substrings > 0 , the number of returned substrings will be no more than max_substrings , otherwise the function will return as many substrings as possible. Int64 Returned value Returns an array of selected substrings of s . Array(String) Examples Usage example sql title=Query SELECT alphaTokens('abca1abc'); response title=Response ┌─alphaTokens('abca1abc')─┐ │ ['abca','abc'] │ └─────────────────────────┘ arrayStringConcat {#arrayStringConcat} Introduced in: v1.1 Concatenates string representations of values listed in the array with the provided separator, which is an optional parameter set to an empty string by default. Syntax sql arrayStringConcat(arr[, separator]) Arguments arr — The array to concatenate. Array(T) separator — Optional. Separator string. By default an empty string. const String Returned value Returns the concatenated string. String Examples Usage example sql title=Query SELECT arrayStringConcat(['12/05/2021', '12:50:00'], ' ') AS DateString; response title=Response ┌─DateString──────────┐ │ 12/05/2021 12:50:00 │ └─────────────────────┘ extractAllGroupsVertical {#extractAllGroupsVertical} Introduced in: v20.5 Matches all groups of a string using a regular expression and returns an array of arrays, where each array includes matching fragments from every group, grouped in order of appearance in the input string. Syntax sql extractAllGroupsVertical(s, regexp) Aliases : extractAllGroups Arguments s — Input string to extract from. String or FixedString regexp — Regular expression to match by. const String or const FixedString Returned value Returns an array of arrays, where each inner array contains the captured groups from one match. Each match produces an array with elements corresponding to the capturing groups in the regular expression (group 1, group 2, etc.). If no matches are found, returns an empty array. Array(Array(String)) Examples Usage example sql title=Query WITH '< Server: nginx < Date: Tue, 22 Jan 2019 00:26:14 GMT < Content-Type: text/html; charset=UTF-8 < Connection: keep-alive ' AS s SELECT extractAllGroupsVertical(s, '< ([\\w\\-]+): ([^\\r\\n]+)');
{"source_file": "splitting-merging-functions.md"}
[ 0.004587567411363125, -0.027568170800805092, -0.04035002738237381, -0.022352037951350212, -0.06341269612312317, 0.05662168934941292, 0.08172648400068283, 0.09666115790605545, -0.056273479014635086, -0.0005522911087609828, -0.015575099736452103, 0.020989665761590004, 0.02727680280804634, -0...
f969ad92-9ae2-4b4c-b7c7-285416194a95
response title=Response [['Server','nginx'],['Date','Tue, 22 Jan 2019 00:26:14 GMT'],['Content-Type','text/html; charset=UTF-8'],['Connection','keep-alive']] ngrams {#ngrams} Introduced in: v21.11 Splits a UTF-8 string into n-grams of ngramsize symbols. Syntax sql ngrams(s, ngram_size) Arguments s — Input string. String or FixedString ngram_size — The size of an n-gram. const UInt8/16/32/64 Returned value Returns an array with n-grams. Array(String) Examples Usage example sql title=Query SELECT ngrams('ClickHouse', 3); response title=Response ['Cli','lic','ick','ckH','kHo','Hou','ous','use'] splitByChar {#splitByChar} Introduced in: v1.1 Splits a string separated by a specified constant string separator of exactly one character into an array of substrings. Empty substrings may be selected if the separator occurs at the beginning or end of the string, or if there are multiple consecutive separators. :::note Setting splitby_max_substrings_includes_remaining_string (default: 0 ) controls if the remaining string is included in the last element of the result array when argument max_substrings > 0 . ::: Empty substrings may be selected when: - A separator occurs at the beginning or end of the string - There are multiple consecutive separators - The original string s is empty Syntax sql splitByChar(separator, s[, max_substrings]) Arguments separator — The separator must be a single-byte character. String s — The string to split. String max_substrings — Optional. If max_substrings > 0 , the returned array will contain at most max_substrings substrings, otherwise the function will return as many substrings as possible. The default value is 0 . Int64 Returned value Returns an array of selected substrings. Array(String) Examples Usage example sql title=Query SELECT splitByChar(',', '1,2,3,abcde'); response title=Response ┌─splitByChar(⋯2,3,abcde')─┐ │ ['1','2','3','abcde'] │ └──────────────────────────┘ splitByNonAlpha {#splitByNonAlpha} Introduced in: v21.9 Splits a string separated by whitespace and punctuation characters into an array of substrings. :::note Setting splitby_max_substrings_includes_remaining_string (default: 0 ) controls if the remaining string is included in the last element of the result array when argument max_substrings > 0 . ::: Syntax sql splitByNonAlpha(s[, max_substrings]) Arguments s — The string to split. String max_substrings — Optional. When max_substrings > 0 , the returned substrings will be no more than max_substrings , otherwise the function will return as many substrings as possible. Default value: 0 . Int64 Returned value Returns an array of selected substrings of s . Array(String) Examples Usage example sql title=Query SELECT splitByNonAlpha('user@domain.com'); response title=Response ['user','domain','com'] splitByRegexp {#splitByRegexp} Introduced in: v21.6
{"source_file": "splitting-merging-functions.md"}
[ -0.04723342880606651, -0.020209701731801033, -0.008840339258313179, -0.02501547895371914, -0.10100853443145752, 0.01839253306388855, 0.09682875871658325, 0.0624266192317009, -0.013584543950855732, -0.03348985314369202, -0.009497071616351604, 0.008790821768343449, -0.008125643245875835, -0....
22dba1ce-a101-4949-9a50-ba25a146b154
Examples Usage example sql title=Query SELECT splitByNonAlpha('user@domain.com'); response title=Response ['user','domain','com'] splitByRegexp {#splitByRegexp} Introduced in: v21.6 Splits a string which is separated by the provided regular expression into an array of substrings. If the provided regular expression is empty, it will split the string into an array of single characters. If no match is found for the regular expression, the string won't be split. Empty substrings may be selected when: - a non-empty regular expression match occurs at the beginning or end of the string - there are multiple consecutive non-empty regular expression matches - the original string string is empty while the regular expression is not empty. :::note Setting splitby_max_substrings_includes_remaining_string (default: 0 ) controls if the remaining string is included in the last element of the result array when argument max_substrings > 0 . ::: Syntax sql splitByRegexp(regexp, s[, max_substrings]) Arguments regexp — Regular expression. Constant. String or FixedString s — The string to split. String max_substrings — Optional. When max_substrings > 0 , the returned substrings will be no more than max_substrings , otherwise the function will return as many substrings as possible. Default value: 0 . Int64 Returned value Returns an array of the selected substrings of s . Array(String) Examples Usage example sql title=Query SELECT splitByRegexp('\\d+', 'a12bc23de345f'); response title=Response ┌─splitByRegex⋯c23de345f')─┐ │ ['a12bc23de345f'] │ └──────────────────────────┘ Empty regexp sql title=Query SELECT splitByRegexp('', 'abcde'); response title=Response ┌─splitByRegexp('', 'abcde')─┐ │ ['a','b','c','d','e'] │ └────────────────────────────┘ splitByString {#splitByString} Introduced in: v1.1 Splits a string with a constant separator consisting of multiple characters into an array of substrings. If the string separator is empty, it will split the string s into an array of single characters. Empty substrings may be selected when: - A non-empty separator occurs at the beginning or end of the string - There are multiple consecutive non-empty separators - The original string s is empty while the separator is not empty :::note Setting splitby_max_substrings_includes_remaining_string (default: 0 ) controls if the remaining string is included in the last element of the result array when argument max_substrings > 0 . ::: Syntax sql splitByString(separator, s[, max_substrings]) Arguments separator — The separator. String s — The string to split. String max_substrings — Optional. When max_substrings > 0 , the returned substrings will be no more than max_substrings , otherwise the function will return as many substrings as possible. Default value: 0 . Int64 Returned value Returns an array of selected substrings of s Array(String) Examples
{"source_file": "splitting-merging-functions.md"}
[ -0.048046428710222244, 0.010355452075600624, 0.07222433388233185, -0.024629341438412666, -0.029293272644281387, -0.007122161332517862, 0.026911254972219467, 0.05745730176568031, -0.013757715933024883, 0.0036735099274665117, -0.025745708495378494, -0.04524650797247887, 0.032977618277072906, ...
a4c56be4-1b4b-4b1c-be8e-22baa6eda430
Returned value Returns an array of selected substrings of s Array(String) Examples Usage example sql title=Query SELECT splitByString(', ', '1, 2 3, 4,5, abcde'); response title=Response ┌─splitByStrin⋯4,5, abcde')─┐ │ ['1','2 3','4,5','abcde'] │ └───────────────────────────┘ Empty separator sql title=Query SELECT splitByString('', 'abcde'); response title=Response ┌─splitByString('', 'abcde')─┐ │ ['a','b','c','d','e'] │ └────────────────────────────┘ splitByWhitespace {#splitByWhitespace} Introduced in: v21.9 Splits a string which is separated by whitespace characters into an array of substrings. :::note Setting splitby_max_substrings_includes_remaining_string (default: 0 ) controls if the remaining string is included in the last element of the result array when argument max_substrings > 0 . ::: Syntax sql splitByWhitespace(s[, max_substrings]) Arguments s — The string to split. String max_substrings — Optional. When max_substrings > 0 , the returned substrings will be no more than max_substrings , otherwise the function will return as many substrings as possible. Default value: 0 . Int64 Returned value Returns an array of the selected substrings of s . Array(String) Examples Usage example sql title=Query SELECT splitByWhitespace(' 1! a, b. '); response title=Response ['1!','a,','b.'] tokens {#tokens} Introduced in: v21.11 Splits a string into tokens using the given tokenizer. The default tokenizer uses non-alphanumeric ASCII characters as separators. In case of the split tokenizer, if the tokens do not form a prefix code , you likely want that the matching prefers longer separators first. To do so, pass the separators in order of descending length. For example, with separators = ['%21', '%'] string %21abc would be tokenized as ['abc'] , whereas separators = ['%', '%21'] would tokenize to ['21ac'] (which is likely not what you wanted). Syntax sql tokens(value[, tokenizer[, ngrams[, separators]]]) Arguments value — The input string. String or FixedString tokenizer — The tokenizer to use. Valid arguments are default , ngram , split , and no_op . Optional, if not set explicitly, defaults to default . const String ngrams — Only relevant if argument tokenizer is ngram : An optional parameter which defines the length of the ngrams. If not set explicitly, defaults to 3 . const UInt8 separators — Only relevant if argument tokenizer is split : An optional parameter which defines the separator strings. If not set explicitly, defaults to [' '] . const Array(String) Returned value Returns the resulting array of tokens from input string. Array Examples Default tokenizer sql title=Query SELECT tokens('test1,;\\\\ test2,;\\\\ test3,;\\\\ test4') AS tokens; response title=Response ['test1','test2','test3','test4'] Ngram tokenizer sql title=Query SELECT tokens('abc def', 'ngram', 3) AS tokens;
{"source_file": "splitting-merging-functions.md"}
[ -0.02335251308977604, -0.03448287770152092, 0.07761386036872864, 0.017260145395994186, -0.04187873378396034, -0.009733609855175018, 0.050272826105356216, 0.03082689270377159, -0.024561243131756783, 0.004040325526148081, -0.05269867554306984, -0.022157985717058182, 0.031215835362672806, -0....
1beba959-0a2b-4f1f-9368-73f793d7baa7
response title=Response ['test1','test2','test3','test4'] Ngram tokenizer sql title=Query SELECT tokens('abc def', 'ngram', 3) AS tokens; response title=Response ['abc','bc ','c d',' de','def']
{"source_file": "splitting-merging-functions.md"}
[ 0.0002021507389144972, -0.037819813936948776, 0.009161391295492649, 0.022069521248340607, -0.10648027807474136, 0.016112560406327248, 0.06283805519342422, 0.08258001506328583, -0.040736790746450424, 0.002045341767370701, 0.00019499989866744727, -0.0745118260383606, 0.01129218004643917, -0....
c2998254-fa0b-4b49-be6b-71d6eec0a86a
description: 'Documentation for Functions for Working with Embedded Dictionaries' sidebar_label: 'Embedded dictionary' slug: /sql-reference/functions/ym-dict-functions title: 'Functions for Working with Embedded Dictionaries' doc_type: 'reference' Functions for Working with Embedded Dictionaries :::note In order for the functions below to work, the server config must specify the paths and addresses for getting all the embedded dictionaries. The dictionaries are loaded at the first call of any of these functions. If the reference lists can't be loaded, an exception is thrown. As such, the examples shown in this section will throw an exception in ClickHouse Fiddle and in quick release and production deployments by default, unless first configured. ::: For information about creating reference lists, see the section "Dictionaries" . Multiple Geobases {#multiple-geobases} ClickHouse supports working with multiple alternative geobases (regional hierarchies) simultaneously, in order to support various perspectives on which countries certain regions belong to. The 'clickhouse-server' config specifies the file with the regional hierarchy: <path_to_regions_hierarchy_file>/opt/geo/regions_hierarchy.txt</path_to_regions_hierarchy_file> Besides this file, it also searches for files nearby that have the _ symbol and any suffix appended to the name (before the file extension). For example, it will also find the file /opt/geo/regions_hierarchy_ua.txt , if present. Here ua is called the dictionary key. For a dictionary without a suffix, the key is an empty string. All the dictionaries are re-loaded during runtime (once every certain number of seconds, as defined in the builtin_dictionaries_reload_interval config parameter, or once an hour by default). However, the list of available dictionaries is defined once, when the server starts. All functions for working with regions have an optional argument at the end – the dictionary key. It is referred to as the geobase. Example: sql regionToCountry(RegionID) – Uses the default dictionary: /opt/geo/regions_hierarchy.txt regionToCountry(RegionID, '') – Uses the default dictionary: /opt/geo/regions_hierarchy.txt regionToCountry(RegionID, 'ua') – Uses the dictionary for the 'ua' key: /opt/geo/regions_hierarchy_ua.txt regionToName {#regiontoname} Accepts a region ID and geobase and returns a string of the name of the region in the corresponding language. If the region with the specified ID does not exist, an empty string is returned. Syntax sql regionToName(id\[, lang\]) Parameters id — Region ID from the geobase. UInt32 . geobase — Dictionary key. See Multiple Geobases . String . Optional. Returned value Name of the region in the corresponding language specified by geobase . String . Otherwise, an empty string. Example Query: sql SELECT regionToName(number::UInt32,'en') FROM numbers(0,5); Result:
{"source_file": "embedded-dict-functions.md"}
[ 0.02732991985976696, -0.0507601834833622, -0.007104202639311552, -0.01788846030831337, 0.0029617417603731155, -0.10039128363132477, -0.009512203745543957, -0.044285137206315994, -0.09630346298217773, -0.03986223787069321, 0.06417009234428406, -0.018963247537612915, 0.03876186162233353, -0....
23ca85e4-e309-400c-ae8f-f4fe908acda9
Otherwise, an empty string. Example Query: sql SELECT regionToName(number::UInt32,'en') FROM numbers(0,5); Result: text ┌─regionToName(CAST(number, 'UInt32'), 'en')─┐ │ │ │ World │ │ USA │ │ Colorado │ │ Boulder County │ └────────────────────────────────────────────┘ regionToCity {#regiontocity} Accepts a region ID from the geobase. If this region is a city or part of a city, it returns the region ID for the appropriate city. Otherwise, returns 0. Syntax sql regionToCity(id [, geobase]) Parameters id — Region ID from the geobase. UInt32 . geobase — Dictionary key. See Multiple Geobases . String . Optional. Returned value Region ID for the appropriate city, if it exists. UInt32 . 0, if there is none. Example Query: sql SELECT regionToName(number::UInt32, 'en'), regionToCity(number::UInt32) AS id, regionToName(id, 'en') FROM numbers(13); Result: response ┌─regionToName(CAST(number, 'UInt32'), 'en')─┬─id─┬─regionToName(regionToCity(CAST(number, 'UInt32')), 'en')─┐ │ │ 0 │ │ │ World │ 0 │ │ │ USA │ 0 │ │ │ Colorado │ 0 │ │ │ Boulder County │ 0 │ │ │ Boulder │ 5 │ Boulder │ │ China │ 0 │ │ │ Sichuan │ 0 │ │ │ Chengdu │ 8 │ Chengdu │ │ America │ 0 │ │ │ North America │ 0 │ │ │ Eurasia │ 0 │ │ │ Asia │ 0 │ │ └────────────────────────────────────────────┴────┴──────────────────────────────────────────────────────────┘ regionToArea {#regiontoarea} Converts a region to an area (type 5 in the geobase). In every other way, this function is the same as 'regionToCity' . Syntax sql regionToArea(id [, geobase]) Parameters
{"source_file": "embedded-dict-functions.md"}
[ 0.12449022382497787, 0.01078520342707634, 0.018520228564739227, 0.005695592146366835, -0.06018764525651932, 0.000262167101027444, 0.048956092447042465, -0.03777341917157173, -0.0358143225312233, -0.08061010390520096, -0.023907987400889397, -0.13006824254989624, 0.04060365632176399, -0.0467...
7f3b819e-3f18-4ae6-b5a3-e060a242c0b0
Converts a region to an area (type 5 in the geobase). In every other way, this function is the same as 'regionToCity' . Syntax sql regionToArea(id [, geobase]) Parameters id — Region ID from the geobase. UInt32 . geobase — Dictionary key. See Multiple Geobases . String . Optional. Returned value Region ID for the appropriate area, if it exists. UInt32 . 0, if there is none. Example Query: sql SELECT DISTINCT regionToName(regionToArea(toUInt32(number), 'ua')) FROM system.numbers LIMIT 15 Result: text ┌─regionToName(regionToArea(toUInt32(number), \'ua\'))─┐ │ │ │ Moscow and Moscow region │ │ St. Petersburg and Leningrad region │ │ Belgorod region │ │ Ivanovsk region │ │ Kaluga region │ │ Kostroma region │ │ Kursk region │ │ Lipetsk region │ │ Orlov region │ │ Ryazan region │ │ Smolensk region │ │ Tambov region │ │ Tver region │ │ Tula region │ └──────────────────────────────────────────────────────┘ regionToDistrict {#regiontodistrict} Converts a region to a federal district (type 4 in the geobase). In every other way, this function is the same as 'regionToCity'. Syntax sql regionToDistrict(id [, geobase]) Parameters id — Region ID from the geobase. UInt32 . geobase — Dictionary key. See Multiple Geobases . String . Optional. Returned value Region ID for the appropriate city, if it exists. UInt32 . 0, if there is none. Example Query: sql SELECT DISTINCT regionToName(regionToDistrict(toUInt32(number), 'ua')) FROM system.numbers LIMIT 15 Result:
{"source_file": "embedded-dict-functions.md"}
[ 0.13892489671707153, -0.01248875167220831, -0.0010260649723932147, -0.022833464667201042, -0.07413333654403687, 0.005959743168205023, -0.0006205282406881452, -0.013287573121488094, -0.025578979402780533, -0.022005055099725723, -0.05394621193408966, -0.06879179179668427, 0.043557509779930115,...
2675cfee-cf22-4c09-8368-e6c5dd328dd8
0, if there is none. Example Query: sql SELECT DISTINCT regionToName(regionToDistrict(toUInt32(number), 'ua')) FROM system.numbers LIMIT 15 Result: text ┌─regionToName(regionToDistrict(toUInt32(number), \'ua\'))─┐ │ │ │ Central federal district │ │ Northwest federal district │ │ South federal district │ │ North Caucases federal district │ │ Privolga federal district │ │ Ural federal district │ │ Siberian federal district │ │ Far East federal district │ │ Scotland │ │ Faroe Islands │ │ Flemish region │ │ Brussels capital region │ │ Wallonia │ │ Federation of Bosnia and Herzegovina │ └──────────────────────────────────────────────────────────┘ regionToCountry {#regiontocountry} Converts a region to a country (type 3 in the geobase). In every other way, this function is the same as 'regionToCity'. Syntax sql regionToCountry(id [, geobase]) Parameters id — Region ID from the geobase. UInt32 . geobase — Dictionary key. See Multiple Geobases . String . Optional. Returned value Region ID for the appropriate country, if it exists. UInt32 . 0, if there is none. Example Query: sql SELECT regionToName(number::UInt32, 'en'), regionToCountry(number::UInt32) AS id, regionToName(id, 'en') FROM numbers(13); Result:
{"source_file": "embedded-dict-functions.md"}
[ 0.11397186666727066, -0.0432983860373497, -0.030688680708408356, -0.01720002293586731, -0.052557338029146194, -0.016590533778071404, 0.02617545612156391, -0.0433976873755455, 0.009835871867835522, -0.03710557892918587, 0.01073999423533678, -0.11317450553178787, 0.06592358648777008, -0.0473...
c4c582d8-c1d4-4110-a9f6-f8aab0e3b31e
0, if there is none. Example Query: sql SELECT regionToName(number::UInt32, 'en'), regionToCountry(number::UInt32) AS id, regionToName(id, 'en') FROM numbers(13); Result: text ┌─regionToName(CAST(number, 'UInt32'), 'en')─┬─id─┬─regionToName(regionToCountry(CAST(number, 'UInt32')), 'en')─┐ │ │ 0 │ │ │ World │ 0 │ │ │ USA │ 2 │ USA │ │ Colorado │ 2 │ USA │ │ Boulder County │ 2 │ USA │ │ Boulder │ 2 │ USA │ │ China │ 6 │ China │ │ Sichuan │ 6 │ China │ │ Chengdu │ 6 │ China │ │ America │ 0 │ │ │ North America │ 0 │ │ │ Eurasia │ 0 │ │ │ Asia │ 0 │ │ └────────────────────────────────────────────┴────┴─────────────────────────────────────────────────────────────┘ regionToContinent {#regiontocontinent} Converts a region to a continent (type 1 in the geobase). In every other way, this function is the same as 'regionToCity'. Syntax sql regionToContinent(id [, geobase]) Parameters id — Region ID from the geobase. UInt32 . geobase — Dictionary key. See Multiple Geobases . String . Optional. Returned value Region ID for the appropriate continent, if it exists. UInt32 . 0, if there is none. Example Query: sql SELECT regionToName(number::UInt32, 'en'), regionToContinent(number::UInt32) AS id, regionToName(id, 'en') FROM numbers(13); Result:
{"source_file": "embedded-dict-functions.md"}
[ 0.09300639480352402, -0.011357534676790237, -0.04556243121623993, -0.009851915761828423, -0.045321013778448105, -0.008527671918272972, 0.10015344619750977, -0.08337653428316116, -0.04119959846138954, -0.022094644606113434, 0.0098270233720541, -0.1304531842470169, 0.061053719371557236, -0.0...
b56e831c-ed2d-4c16-8083-603b5306e58d
0, if there is none. Example Query: sql SELECT regionToName(number::UInt32, 'en'), regionToContinent(number::UInt32) AS id, regionToName(id, 'en') FROM numbers(13); Result: text ┌─regionToName(CAST(number, 'UInt32'), 'en')─┬─id─┬─regionToName(regionToContinent(CAST(number, 'UInt32')), 'en')─┐ │ │ 0 │ │ │ World │ 0 │ │ │ USA │ 10 │ North America │ │ Colorado │ 10 │ North America │ │ Boulder County │ 10 │ North America │ │ Boulder │ 10 │ North America │ │ China │ 12 │ Asia │ │ Sichuan │ 12 │ Asia │ │ Chengdu │ 12 │ Asia │ │ America │ 9 │ America │ │ North America │ 10 │ North America │ │ Eurasia │ 11 │ Eurasia │ │ Asia │ 12 │ Asia │ └────────────────────────────────────────────┴────┴───────────────────────────────────────────────────────────────┘ regionToTopContinent {#regiontotopcontinent} Finds the highest continent in the hierarchy for the region. Syntax sql regionToTopContinent(id[, geobase]) Parameters id — Region ID from the geobase. UInt32 . geobase — Dictionary key. See Multiple Geobases . String . Optional. Returned value Identifier of the top level continent (the latter when you climb the hierarchy of regions). UInt32 . 0, if there is none. Example Query: sql SELECT regionToName(number::UInt32, 'en'), regionToTopContinent(number::UInt32) AS id, regionToName(id, 'en') FROM numbers(13); Result:
{"source_file": "embedded-dict-functions.md"}
[ 0.09134049713611603, -0.025708315894007683, -0.052478592842817307, -0.058435358107089996, -0.04260426387190819, -0.032378606498241425, 0.08435944467782974, -0.05498707666993141, -0.07825727015733719, 0.013199214823544025, -0.02244216576218605, -0.08611132204532623, 0.057769499719142914, -0...
c8d29782-1e3f-4556-a9e2-54c5de44e100
0, if there is none. Example Query: sql SELECT regionToName(number::UInt32, 'en'), regionToTopContinent(number::UInt32) AS id, regionToName(id, 'en') FROM numbers(13); Result: text ┌─regionToName(CAST(number, 'UInt32'), 'en')─┬─id─┬─regionToName(regionToTopContinent(CAST(number, 'UInt32')), 'en')─┐ │ │ 0 │ │ │ World │ 0 │ │ │ USA │ 9 │ America │ │ Colorado │ 9 │ America │ │ Boulder County │ 9 │ America │ │ Boulder │ 9 │ America │ │ China │ 11 │ Eurasia │ │ Sichuan │ 11 │ Eurasia │ │ Chengdu │ 11 │ Eurasia │ │ America │ 9 │ America │ │ North America │ 9 │ America │ │ Eurasia │ 11 │ Eurasia │ │ Asia │ 11 │ Eurasia │ └────────────────────────────────────────────┴────┴──────────────────────────────────────────────────────────────────┘ regionToPopulation {#regiontopopulation} Gets the population for a region. The population can be recorded in files with the geobase. See the section "Dictionaries" . If the population is not recorded for the region, it returns 0. In the geobase, the population might be recorded for child regions, but not for parent regions. Syntax sql regionToPopulation(id[, geobase]) Parameters id — Region ID from the geobase. UInt32 . geobase — Dictionary key. See Multiple Geobases . String . Optional. Returned value Population for the region. UInt32 . 0, if there is none. Example Query: sql SELECT regionToName(number::UInt32, 'en'), regionToPopulation(number::UInt32) AS id, regionToName(id, 'en') FROM numbers(13); Result:
{"source_file": "embedded-dict-functions.md"}
[ 0.09114677459001541, -0.04255818948149681, -0.039053045213222504, -0.0037391213700175285, -0.03744244948029518, -0.010221586562693119, 0.04838672652840614, -0.0967947393655777, -0.051212530583143234, -0.012356004677712917, 0.06036677584052086, -0.1391068696975708, 0.052259575575590134, -0....
f068ec03-e3cb-4c5e-8844-e105f8d4f86d
0, if there is none. Example Query: sql SELECT regionToName(number::UInt32, 'en'), regionToPopulation(number::UInt32) AS id, regionToName(id, 'en') FROM numbers(13); Result: text ┌─regionToName(CAST(number, 'UInt32'), 'en')─┬─population─┐ │ │ 0 │ │ World │ 4294967295 │ │ USA │ 330000000 │ │ Colorado │ 5700000 │ │ Boulder County │ 330000 │ │ Boulder │ 100000 │ │ China │ 1500000000 │ │ Sichuan │ 83000000 │ │ Chengdu │ 20000000 │ │ America │ 1000000000 │ │ North America │ 600000000 │ │ Eurasia │ 4294967295 │ │ Asia │ 4294967295 │ └────────────────────────────────────────────┴────────────┘ regionIn {#regionin} Checks whether a lhs region belongs to a rhs region. Returns a UInt8 number equal to 1 if it belongs, or 0 if it does not belong. Syntax sql regionIn(lhs, rhs\[, geobase\]) Parameters lhs — Lhs region ID from the geobase. UInt32 . rhs — Rhs region ID from the geobase. UInt32 . geobase — Dictionary key. See Multiple Geobases . String . Optional. Returned value 1, if it belongs. UInt8 . 0, if it doesn't belong. Implementation details The relationship is reflexive – any region also belongs to itself. Example Query: sql SELECT regionToName(n1.number::UInt32, 'en') || (regionIn(n1.number::UInt32, n2.number::UInt32) ? ' is in ' : ' is not in ') || regionToName(n2.number::UInt32, 'en') FROM numbers(1,2) AS n1 CROSS JOIN numbers(1,5) AS n2; Result: text World is in World World is not in USA World is not in Colorado World is not in Boulder County World is not in Boulder USA is in World USA is in USA USA is not in Colorado USA is not in Boulder County USA is not in Boulder regionHierarchy {#regionhierarchy} Accepts a UInt32 number – the region ID from the geobase. Returns an array of region IDs consisting of the passed region and all parents along the chain. Syntax sql regionHierarchy(id\[, geobase\]) Parameters id — Region ID from the geobase. UInt32 . geobase — Dictionary key. See Multiple Geobases . String . Optional. Returned value Array of region IDs consisting of the passed region and all parents along the chain. Array ( UInt32 ). Example Query: sql SELECT regionHierarchy(number::UInt32) AS arr, arrayMap(id -> regionToName(id, 'en'), arr) FROM numbers(5); Result:
{"source_file": "embedded-dict-functions.md"}
[ 0.071965791285038, 0.018938187509775162, 0.010236436501145363, -0.023689858615398407, -0.010646517388522625, -0.052981045097112656, 0.08013852685689926, -0.08667750656604767, -0.053710635751485825, -0.04308246448636055, -0.0066381581127643585, -0.10214225202798843, 0.03863157331943512, -0....
f11a22e0-097b-4c53-ac30-4bd7e5448669
Example Query: sql SELECT regionHierarchy(number::UInt32) AS arr, arrayMap(id -> regionToName(id, 'en'), arr) FROM numbers(5); Result: text ┌─arr────────────┬─arrayMap(lambda(tuple(id), regionToName(id, 'en')), regionHierarchy(CAST(number, 'UInt32')))─┐ │ [] │ [] │ │ [1] │ ['World'] │ │ [2,10,9,1] │ ['USA','North America','America','World'] │ │ [3,2,10,9,1] │ ['Colorado','USA','North America','America','World'] │ │ [4,3,2,10,9,1] │ ['Boulder County','Colorado','USA','North America','America','World'] │ └────────────────┴──────────────────────────────────────────────────────────────────────────────────────────────┘
{"source_file": "embedded-dict-functions.md"}
[ 0.1406991183757782, 0.006173544097691774, 0.03245912119746208, -0.06134621053934097, -0.02843322791159153, -0.03477925807237625, 0.06052624061703682, -0.11332207173109055, -0.08161492645740509, 0.005970323923975229, -0.0004969077417626977, -0.05011807382106781, 0.04631241410970688, -0.0257...