id
stringlengths
36
36
document
stringlengths
3
3k
metadata
stringlengths
23
69
embeddings
listlengths
384
384
06971cf4-534f-451c-b541-0eea68cfb6ca
response title=Response 1 2 hilbertEncode {#hilbertEncode} Introduced in: v24.6 Calculates code for Hilbert Curve for a list of unsigned integers. The function has two modes of operation: - Simple - Expanded Simple mode Accepts up to 2 unsigned integers as arguments and produces a UInt64 code. Expanded mode Accepts a range mask ( Tuple ) as the first argument and up to 2 unsigned integers as other arguments. Each number in the mask configures the number of bits by which the corresponding argument will be shifted left, effectively scaling the argument within its range. Syntax ```sql -- Simplified mode hilbertEncode(args) -- Expanded mode hilbertEncode(range_mask, args) ``` Arguments args โ€” Up to two UInt values or columns of type UInt . UInt8/16/32/64 range_mask โ€” For the expanded mode, up to two UInt values or columns of type UInt . UInt8/16/32/64 Returned value Returns a UInt64 code. UInt64 Examples Simple mode sql title=Query SELECT hilbertEncode(3, 4) response title=Response 31 Expanded mode sql title=Query -- Range expansion can be beneficial when you need a similar distribution for -- arguments with wildly different ranges (or cardinality). -- For example: 'IP Address' (0...FFFFFFFF) and 'Country code' (0...FF). -- Note: tuple size must be equal to the number of the other arguments. SELECT hilbertEncode((10, 6), 1024, 16) response title=Response 4031541586602 Single argument sql title=Query -- For a single argument without a tuple, the function returns the argument -- itself as the Hilbert index, since no dimensional mapping is needed. SELECT hilbertEncode(1) response title=Response 1 Expanded single argument sql title=Query -- If a single argument is provided with a tuple specifying bit shifts, the function -- shifts the argument left by the specified number of bits. SELECT hilbertEncode(tuple(2), 128) response title=Response 512 Column usage ```sql title=Query -- First create the table and insert some data CREATE TABLE hilbert_numbers( n1 UInt32, n2 UInt32 ) ENGINE=MergeTree() ORDER BY n1; insert into hilbert_numbers (*) values(1, 2); -- Use column names instead of constants as function arguments SELECT hilbertEncode(n1, n2) FROM hilbert_numbers; ``` response title=Response 13 mortonDecode {#mortonDecode} Introduced in: v24.6 Decodes a Morton encoding (ZCurve) into the corresponding unsigned integer tuple. As with the mortonEncode function, this function has two modes of operation: - Simple - Expanded Simple mode Accepts a resulting tuple size as the first argument and the code as the second argument. Expanded mode Accepts a range mask (tuple) as the first argument and the code as the second argument. Each number in the mask configures the amount of range shrink: 1 - no shrink 2 - 2x shrink 3 - 3x shrink โ‹ฎ Up to 8x shrink.
{"source_file": "encoding-functions.md"}
[ 0.026610905304551125, -0.018869269639253616, -0.0842558890581131, 0.01875135488808155, -0.08789822459220886, -0.04874962568283081, 0.02784605510532856, 0.04141439497470856, -0.113011933863163, -0.09666869789361954, 0.051272667944431305, -0.0923350378870964, 0.004432070534676313, -0.0868450...
cc06a55e-141f-4ea6-a95c-fc22b6b88637
1 - no shrink 2 - 2x shrink 3 - 3x shrink โ‹ฎ Up to 8x shrink. Range expansion can be beneficial when you need a similar distribution for arguments with wildly different ranges (or cardinality). For example: 'IP Address' (0...FFFFFFFF) and 'Country code' (0...FF) . As with the encode function, this is limited to 8 numbers at most. Syntax ```sql -- Simple mode mortonDecode(tuple_size, code) -- Expanded mode mortonDecode(range_mask, code) ``` Arguments tuple_size โ€” Integer value no more than 8. UInt8/16/32/64 range_mask โ€” For the expanded mode, the mask for each argument. The mask is a tuple of unsigned integers. Each number in the mask configures the amount of range shrink. Tuple(UInt8/16/32/64) code โ€” UInt64 code. UInt64 Returned value Returns a tuple of the specified size. Tuple(UInt64) Examples Simple mode sql title=Query SELECT mortonDecode(3, 53) response title=Response ["1", "2", "3"] Single argument sql title=Query SELECT mortonDecode(1, 1) response title=Response ["1"] Expanded mode, shrinking one argument sql title=Query SELECT mortonDecode(tuple(2), 32768) response title=Response ["128"] Column usage ```sql title=Query -- First create the table and insert some data CREATE TABLE morton_numbers( n1 UInt32, n2 UInt32, n3 UInt16, n4 UInt16, n5 UInt8, n6 UInt8, n7 UInt8, n8 UInt8 ) ENGINE=MergeTree() ORDER BY n1; INSERT INTO morton_numbers (*) values(1, 2, 3, 4, 5, 6, 7, 8); -- Use column names instead of constants as function arguments SELECT untuple(mortonDecode(8, mortonEncode(n1, n2, n3, n4, n5, n6, n7, n8))) FROM morton_numbers; ``` response title=Response 1 2 3 4 5 6 7 8 mortonEncode {#mortonEncode} Introduced in: v24.6 Calculates the Morton encoding (ZCurve) for a list of unsigned integers. The function has two modes of operation: - Simple - Expanded * Simple mode Accepts up to 8 unsigned integers as arguments and produces a UInt64 code. Expanded mode Accepts a range mask ( Tuple ) as the first argument and up to 8 unsigned integers as other arguments. Each number in the mask configures the amount of range expansion: * 1 - no expansion * 2 - 2x expansion * 3 - 3x expansion โ‹ฎ * Up to 8x expansion. Syntax ```sql -- Simplified mode mortonEncode(args) -- Expanded mode mortonEncode(range_mask, args) ``` Arguments args โ€” Up to 8 unsigned integers or columns of the aforementioned type. UInt8/16/32/64 range_mask โ€” For the expanded mode, the mask for each argument. The mask is a tuple of unsigned integers from 1 - 8 . Each number in the mask configures the amount of range shrink. Tuple(UInt8/16/32/64) Returned value Returns a UInt64 code. UInt64 Examples Simple mode sql title=Query SELECT mortonEncode(1, 2, 3) response title=Response 53 Expanded mode
{"source_file": "encoding-functions.md"}
[ 0.03861105814576149, 0.027010874822735786, -0.051126204431056976, 0.004011845216155052, -0.03251200169324875, -0.007211251650005579, 0.020615793764591217, 0.00851998571306467, -0.10175998508930206, -0.036254022270441055, -0.0015557182487100363, -0.017404453828930855, 0.03382384404540062, -...
1c665ba8-5ca9-4e45-9861-f6d46d041821
Returned value Returns a UInt64 code. UInt64 Examples Simple mode sql title=Query SELECT mortonEncode(1, 2, 3) response title=Response 53 Expanded mode sql title=Query -- Range expansion can be beneficial when you need a similar distribution for -- arguments with wildly different ranges (or cardinality) -- For example: 'IP Address' (0...FFFFFFFF) and 'Country code' (0...FF). -- Note: the Tuple size must be equal to the number of the other arguments. SELECT mortonEncode((1,2), 1024, 16) response title=Response 1572864 Single argument sql title=Query -- Morton encoding for one argument is always the argument itself SELECT mortonEncode(1) response title=Response 1 Expanded single argument sql title=Query SELECT mortonEncode(tuple(2), 128) response title=Response 32768 Column usage ```sql title=Query -- First create the table and insert some data CREATE TABLE morton_numbers( n1 UInt32, n2 UInt32, n3 UInt16, n4 UInt16, n5 UInt8, n6 UInt8, n7 UInt8, n8 UInt8 ) ENGINE=MergeTree() ORDER BY n1; INSERT INTO morton_numbers (*) values(1, 2, 3, 4, 5, 6, 7, 8); -- Use column names instead of constants as function arguments SELECT mortonEncode(n1, n2, n3, n4, n5, n6, n7, n8) FROM morton_numbers; ``` response title=Response 2155374165 sqidDecode {#sqidDecode} Introduced in: v24.1 Transforms a sqid back into an array of numbers. Syntax sql sqidDecode(sqid) Arguments sqid โ€” The sqid to decode. String Returned value Returns an array of numbers from sqid . Array(UInt64) Examples Usage example sql title=Query SELECT sqidDecode('gXHfJ1C6dN'); response title=Response โ”Œโ”€sqidDecode('gXHfJ1C6dN')โ”€โ”€โ”€โ”€โ”€โ” โ”‚ [1, 2, 3, 4, 5] โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ sqidEncode {#sqidEncode} Introduced in: v24.1 Transforms numbers into a sqid , a Youtube-like ID string. Syntax sql sqidEncode(n1[, n2, ...]) Aliases : sqid Arguments n1[, n2, ...] โ€” Arbitrarily many numbers. UInt8/16/32/64 Returned value Returns a hash ID String Examples Usage example sql title=Query SELECT sqidEncode(1, 2, 3, 4, 5); response title=Response โ”Œโ”€sqidEncode(1, 2, 3, 4, 5)โ”€โ” โ”‚ gXHfJ1C6dN โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ unbin {#unbin} Introduced in: v21.8 Interprets each pair of binary digits (in the argument) as a number and converts it to the byte represented by the number. The functions performs the opposite operation to bin. For a numeric argument unbin() does not return the inverse of bin() . If you want to convert the result to a number, you can use the reverse and reinterpretAs<Type> functions. :::note If unbin is invoked from within the clickhouse-client , binary strings are displayed using UTF-8. :::
{"source_file": "encoding-functions.md"}
[ 0.03601576015353203, -0.02477267012000084, -0.0810633972287178, 0.012251435779035091, -0.10190901905298233, -0.007147625088691711, 0.017757117748260498, -0.0218658447265625, -0.0261611919850111, -0.038976039737463, -0.0036191237159073353, -0.031101059168577194, 0.003258912591263652, -0.128...
df66397c-0682-478f-acc7-98a104402804
:::note If unbin is invoked from within the clickhouse-client , binary strings are displayed using UTF-8. ::: Supports binary digits 0 and 1 . The number of binary digits does not have to be multiples of eight. If the argument string contains anything other than binary digits, the result is undefined (no exception is thrown). Syntax sql unbin(arg) Arguments arg โ€” A string containing any number of binary digits. String Returned value Returns a binary string (BLOB). String Examples Basic usage sql title=Query SELECT UNBIN('001100000011000100110010'), UNBIN('0100110101111001010100110101000101001100') response title=Response โ”Œโ”€unbin('001100000011000100110010')โ”€โ”ฌโ”€unbin('0100110101111001010100110101000101001100')โ”€โ” โ”‚ 012 โ”‚ MySQL โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Convert to number sql title=Query SELECT reinterpretAsUInt64(reverse(unbin('1110'))) AS num response title=Response โ”Œโ”€numโ”€โ” โ”‚ 14 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”˜ unhex {#unhex} Introduced in: v1.1 Performs the opposite operation of hex . It interprets each pair of hexadecimal digits (in the argument) as a number and converts it to the byte represented by the number. The returned value is a binary string (BLOB). If you want to convert the result to a number, you can use the reverse and reinterpretAs<Type> functions. :::note clickhouse-client interprets strings as UTF-8. This may cause that values returned by hex to be displayed surprisingly. ::: Supports both uppercase and lowercase letters A-F . The number of hexadecimal digits does not have to be even. If it is odd, the last digit is interpreted as the least significant half of the 00-0F byte. If the argument string contains anything other than hexadecimal digits, some implementation-defined result is returned (an exception isn't thrown). For a numeric argument the inverse of hex(N) is not performed by unhex(). Syntax sql unhex(arg) Arguments arg โ€” A string containing any number of hexadecimal digits. String or FixedString Returned value Returns a binary string (BLOB). String Examples Basic usage sql title=Query SELECT unhex('303132'), UNHEX('4D7953514C') response title=Response โ”Œโ”€unhex('303132')โ”€โ”ฌโ”€unhex('4D7953514C')โ”€โ” โ”‚ 012 โ”‚ MySQL โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Convert to number sql title=Query SELECT reinterpretAsUInt64(reverse(unhex('FFF'))) AS num response title=Response โ”Œโ”€โ”€numโ”€โ” โ”‚ 4095 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
{"source_file": "encoding-functions.md"}
[ 0.006795930210500956, -0.026264803484082222, -0.05764179676771164, 0.04729091376066208, -0.1308906227350235, -0.01490236446261406, 0.11481398344039917, -0.035990409553050995, -0.04389657825231552, -0.019003557041287422, -0.009735933504998684, -0.02651168219745159, 0.06643662601709366, -0.0...
fdd7a546-1477-4bcc-a457-dab79993093e
description: 'Documentation for functions used for working with ULIDs' sidebar_label: 'ULIDs' slug: /sql-reference/functions/ulid-functions title: 'Functions for working with ULIDs' doc_type: 'reference' Functions for working with ULIDs :::note The documentation below is generated from the system.functions system table. ::: ULIDStringToDateTime {#ULIDStringToDateTime} Introduced in: v23.3 This function extracts the timestamp from a [ULID]((https://github.com/ulid/spec). Syntax sql ULIDStringToDateTime(ulid[, timezone]) Arguments ulid โ€” Input ULID. String or FixedString(26) timezone โ€” Optional. Timezone name for the returned value. String Returned value Timestamp with milliseconds precision. DateTime64(3) Examples Usage example sql title=Query SELECT ULIDStringToDateTime('01GNB2S2FGN2P93QPXDNB4EN2R') response title=Response โ”Œโ”€ULIDStringToDateTime('01GNB2S2FGN2P93QPXDNB4EN2R')โ”€โ” โ”‚ 2022-12-28 00:40:37.616 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ generateULID {#generateULID} Introduced in: v23.2 Generates a Universally Unique Lexicographically Sortable Identifier (ULID) . Syntax sql generateULID([x]) Arguments x โ€” Optional. An expression resulting in any of the supported data types. The resulting value is discarded, but the expression itself if used for bypassing common subexpression elimination if the function is called multiple times in one query. Any Returned value Returns a ULID. FixedString(26) Examples Usage example sql title=Query SELECT generateULID() response title=Response โ”Œโ”€generateULID()โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ 01GNB2S2FGN2P93QPXDNB4EN2R โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Usage example if it is needed to generate multiple values in one row sql title=Query SELECT generateULID(1), generateULID(2) response title=Response โ”Œโ”€generateULID(1)โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€generateULID(2)โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ 01GNB2SGG4RHKVNT9ZGA4FFMNP โ”‚ 01GNB2SGG4V0HMQVH4VBVPSSRB โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ See also {#see-also} UUID
{"source_file": "ulid-functions.md"}
[ -0.04581413418054581, 0.028879592195153236, -0.04184437915682793, 0.05900616943836212, -0.03350672125816345, 0.0065382388420403, 0.03654816746711731, 0.06867366284132004, -0.0024567428044974804, -0.041791610419750214, 0.006849338300526142, -0.07468260824680328, 0.01872342824935913, -0.1348...
226ba8ef-6243-468f-a9c9-2f717f48011f
description: 'Documentation for Tuple Map Functions' sidebar_label: 'Maps' slug: /sql-reference/functions/tuple-map-functions title: 'Map Functions' doc_type: 'reference' map {#map} Creates a value of type Map(key, value) from key-value pairs. Syntax sql map(key1, value1[, key2, value2, ...]) Arguments key_n โ€” The keys of the map entries. Any type supported as key type of Map . value_n โ€” The values of the map entries. Any type supported as value type of Map . Returned value A map containing key:value pairs. Map(key, value) . Examples Query: sql SELECT map('key1', number, 'key2', number * 2) FROM numbers(3); Result: text โ”Œโ”€map('key1', number, 'key2', multiply(number, 2))โ”€โ” โ”‚ {'key1':0,'key2':0} โ”‚ โ”‚ {'key1':1,'key2':2} โ”‚ โ”‚ {'key1':2,'key2':4} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ mapFromArrays {#mapfromarrays} Creates a map from an array or map of keys and an array or map of values. The function is a convenient alternative to syntax CAST([...], 'Map(key_type, value_type)') . For example, instead of writing - CAST((['aa', 'bb'], [4, 5]), 'Map(String, UInt32)') , or - CAST([('aa',4), ('bb',5)], 'Map(String, UInt32)') you can write mapFromArrays(['aa', 'bb'], [4, 5]) . Syntax sql mapFromArrays(keys, values) Alias: MAP_FROM_ARRAYS(keys, values) Arguments keys โ€” Array or map of keys to create the map from Array or Map . If keys is an array, we accept Array(Nullable(T)) or Array(LowCardinality(Nullable(T))) as its type as long as it doesn't contain NULL value. values - Array or map of values to create the map from Array or Map . Returned value A map with keys and values constructed from the key array and value array/map. Example Query: sql SELECT mapFromArrays(['a', 'b', 'c'], [1, 2, 3]) Result: response โ”Œโ”€mapFromArrays(['a', 'b', 'c'], [1, 2, 3])โ”€โ” โ”‚ {'a':1,'b':2,'c':3} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ mapFromArrays also accepts arguments of type Map . These are cast to array of tuples during execution. sql SELECT mapFromArrays([1, 2, 3], map('a', 1, 'b', 2, 'c', 3)) Result: response โ”Œโ”€mapFromArrays([1, 2, 3], map('a', 1, 'b', 2, 'c', 3))โ”€โ” โ”‚ {1:('a',1),2:('b',2),3:('c',3)} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ sql SELECT mapFromArrays(map('a', 1, 'b', 2, 'c', 3), [1, 2, 3]) Result: response โ”Œโ”€mapFromArrays(map('a', 1, 'b', 2, 'c', 3), [1, 2, 3])โ”€โ” โ”‚ {('a',1):1,('b',2):2,('c',3):3} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ extractKeyValuePairs {#extractkeyvaluepairs}
{"source_file": "tuple-map-functions.md"}
[ 0.021994272246956825, 0.004811809863895178, 0.034080300480127335, -0.019438179209828377, -0.06337235122919083, 0.014927630312740803, 0.08278912305831909, -0.009624790400266647, -0.08629045635461807, -0.020390339195728302, 0.030949756503105164, 0.0070617529563605785, 0.05280963331460953, -0...
5f75383d-a30c-4d8b-9f2d-a1bb39e72373
extractKeyValuePairs {#extractkeyvaluepairs} Converts a string of key-value pairs to a Map(String, String) . Parsing is tolerant towards noise (e.g. log files). Key-value pairs in the input string consist of a key, followed by a key-value delimiter, and a value. Key value pairs are separated by a pair delimiter. Keys and values can be quoted. Syntax sql extractKeyValuePairs(data[, key_value_delimiter[, pair_delimiter[, quoting_character[, unexpected_quoting_character_strategy]]]) Alias: - str_to_map - mapFromString Arguments data - String to extract key-value pairs from. String or FixedString . key_value_delimiter - Single character delimiting keys and values. Defaults to : . String or FixedString . pair_delimiters - Set of character delimiting pairs. Defaults to , , and ; . String or FixedString . quoting_character - Single character used as quoting character. Defaults to " . String or FixedString . unexpected_quoting_character_strategy - Strategy to handle quoting characters in unexpected places during read_key and read_value phase. Possible values: "invalid", "accept" and "promote". Invalid will discard key/value and transition back to WAITING_KEY state. Accept will treat it as a normal character. Promote will transition to READ_QUOTED_{KEY/VALUE} state and start from next character. Returned values A of key-value pairs. Type: Map(String, String) Examples Query sql SELECT extractKeyValuePairs('name:neymar, age:31 team:psg,nationality:brazil') AS kv Result: Result: โ”Œโ”€kvโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ {'name':'neymar','age':'31','team':'psg','nationality':'brazil'} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ With a single quote ' as quoting character: sql SELECT extractKeyValuePairs('name:\'neymar\';\'age\':31;team:psg;nationality:brazil,last_key:last_value', ':', ';,', '\'') AS kv Result: text โ”Œโ”€kvโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ {'name':'neymar','age':'31','team':'psg','nationality':'brazil','last_key':'last_value'} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ unexpected_quoting_character_strategy examples: unexpected_quoting_character_strategy=invalid sql SELECT extractKeyValuePairs('name"abc:5', ':', ' ,;', '\"', 'INVALID') AS kv; text โ”Œโ”€kvโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ {'abc':'5'} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ sql SELECT extractKeyValuePairs('name"abc":5', ':', ' ,;', '\"', 'INVALID') AS kv; text โ”Œโ”€kvโ”€โ”€โ” โ”‚ {} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”˜ unexpected_quoting_character_strategy=accept sql SELECT extractKeyValuePairs('name"abc:5', ':', ' ,;', '\"', 'ACCEPT') AS kv; text โ”Œโ”€kvโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ {'name"abc':'5'} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
{"source_file": "tuple-map-functions.md"}
[ 0.024412767961621284, 0.015346899628639221, -0.03199950233101845, -0.034443262964487076, -0.04919637367129326, -0.007254085037857294, 0.09681510925292969, 0.05739499628543854, -0.05246937647461891, -0.0003421243163757026, 0.023610049858689308, -0.007867769338190556, 0.0594504252076149, -0....
0528956b-aa1f-406b-a3ff-efbbe22555ad
sql SELECT extractKeyValuePairs('name"abc:5', ':', ' ,;', '\"', 'ACCEPT') AS kv; text โ”Œโ”€kvโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ {'name"abc':'5'} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ sql SELECT extractKeyValuePairs('name"abc":5', ':', ' ,;', '\"', 'ACCEPT') AS kv; text โ”Œโ”€kvโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ {'name"abc"':'5'} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ unexpected_quoting_character_strategy=promote sql SELECT extractKeyValuePairs('name"abc:5', ':', ' ,;', '\"', 'PROMOTE') AS kv; text โ”Œโ”€kvโ”€โ”€โ” โ”‚ {} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”˜ sql SELECT extractKeyValuePairs('name"abc":5', ':', ' ,;', '\"', 'PROMOTE') AS kv; text โ”Œโ”€kvโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ {'abc':'5'} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Escape sequences without escape sequences support: sql SELECT extractKeyValuePairs('age:a\\x0A\\n\\0') AS kv Result: text โ”Œโ”€kvโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ {'age':'a\\x0A\\n\\0'} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ To restore a map string key-value pairs serialized with toString : sql SELECT map('John', '33', 'Paula', '31') AS m, toString(m) AS map_serialized, extractKeyValuePairs(map_serialized, ':', ',', '\'') AS map_restored FORMAT Vertical; Result: response Row 1: โ”€โ”€โ”€โ”€โ”€โ”€ m: {'John':'33','Paula':'31'} map_serialized: {'John':'33','Paula':'31'} map_restored: {'John':'33','Paula':'31'} extractKeyValuePairsWithEscaping {#extractkeyvaluepairswithescaping} Same as extractKeyValuePairs but supports escaping. Supported escape sequences: \x , \N , \a , \b , \e , \f , \n , \r , \t , \v and \0 . Non standard escape sequences are returned as it is (including the backslash) unless they are one of the following: \\ , ' , " , backtick , / , = or ASCII control characters (c <= 31). This function will satisfy the use case where pre-escaping and post-escaping are not suitable. For instance, consider the following input string: a: "aaaa\"bbb" . The expected output is: a: aaaa\"bbbb . - Pre-escaping: Pre-escaping it will output: a: "aaaa"bbb" and extractKeyValuePairs will then output: a: aaaa - Post-escaping: extractKeyValuePairs will output a: aaaa\ and post-escaping will keep it as it is. Leading escape sequences will be skipped in keys and will be considered invalid for values. Examples Escape sequences with escape sequence support turned on: sql SELECT extractKeyValuePairsWithEscaping('age:a\\x0A\\n\\0') AS kv Result: response โ”Œโ”€kvโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ {'age':'a\n\n\0'} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ mapAdd {#mapadd} Collect all the keys and sum corresponding values. Syntax sql mapAdd(arg1, arg2 [, ...]) Arguments Arguments are maps or tuples of two arrays , where items in the first array represent keys, and the second array contains values for the each key. All key arrays should have same type, and all value arrays should contain items which are promoted to the one type ( Int64 , UInt64 or Float64 ). The common promoted type is used as a type for the result array. Returned value
{"source_file": "tuple-map-functions.md"}
[ -0.04468165338039398, 0.02865953929722309, 0.06742354482412338, 0.042137566953897476, -0.06447409838438034, 0.04342962056398392, 0.07547779381275177, -0.03523438796401024, -0.02301936224102974, -0.0014968867180868983, 0.0910462811589241, -0.0748228207230568, 0.0864333063364029, -0.06114669...
495b4c13-b847-4690-8b44-f4fc4147a49c
Returned value Depending on the arguments returns one map or tuple , where the first array contains the sorted keys and the second array contains values. Example Query with Map type: sql SELECT mapAdd(map(1,1), map(1,1)); Result: text โ”Œโ”€mapAdd(map(1, 1), map(1, 1))โ”€โ” โ”‚ {1:2} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Query with a tuple: sql SELECT mapAdd(([toUInt8(1), 2], [1, 1]), ([toUInt8(1), 2], [1, 1])) AS res, toTypeName(res) AS type; Result: text โ”Œโ”€resโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€typeโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ ([1,2],[2,2]) โ”‚ Tuple(Array(UInt8), Array(UInt64)) โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ mapSubtract {#mapsubtract} Collect all the keys and subtract corresponding values. Syntax sql mapSubtract(Tuple(Array, Array), Tuple(Array, Array) [, ...]) Arguments Arguments are maps or tuples of two arrays , where items in the first array represent keys, and the second array contains values for the each key. All key arrays should have same type, and all value arrays should contain items which are promote to the one type ( Int64 , UInt64 or Float64 ). The common promoted type is used as a type for the result array. Returned value Depending on the arguments returns one map or tuple , where the first array contains the sorted keys and the second array contains values. Example Query with Map type: sql SELECT mapSubtract(map(1,1), map(1,1)); Result: text โ”Œโ”€mapSubtract(map(1, 1), map(1, 1))โ”€โ” โ”‚ {1:0} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Query with a tuple map: sql SELECT mapSubtract(([toUInt8(1), 2], [toInt32(1), 1]), ([toUInt8(1), 2], [toInt32(2), 1])) AS res, toTypeName(res) AS type; Result: text โ”Œโ”€resโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€typeโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ ([1,2],[-1,0]) โ”‚ Tuple(Array(UInt8), Array(Int64)) โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ mapPopulateSeries {#mappopulateseries} Fills missing key-value pairs in a map with integer keys. To support extending the keys beyond the largest value, a maximum key can be specified. More specifically, the function returns a map in which the the keys form a series from the smallest to the largest key (or max argument if it specified) with step size of 1, and corresponding values. If no value is specified for a key, a default value is used as value. In case keys repeat, only the first value (in order of appearance) is associated with the key. Syntax sql mapPopulateSeries(map[, max]) mapPopulateSeries(keys, values[, max]) For array arguments the number of elements in keys and values must be the same for each row. Arguments Arguments are Maps or two Arrays , where the first and second array contains keys and values for the each key. Mapped arrays: map โ€” Map with integer keys. Map . or keys โ€” Array of keys. Array ( Int ). values โ€” Array of values. Array ( Int ).
{"source_file": "tuple-map-functions.md"}
[ 0.057276349514722824, 0.02243640460073948, -0.016604147851467133, -0.00948554277420044, -0.039073243737220764, -0.004736210685223341, 0.11962375789880753, -0.016493093222379684, -0.07896950840950012, -0.002246498130261898, -0.016042465344071388, 0.005381484515964985, 0.05839533358812332, -...
dfb0e315-3b14-4b94-bc26-0c724812bf26
Mapped arrays: map โ€” Map with integer keys. Map . or keys โ€” Array of keys. Array ( Int ). values โ€” Array of values. Array ( Int ). max โ€” Maximum key value. Optional. Int8, Int16, Int32, Int64, Int128, Int256 . Returned value Depending on the arguments a Map or a Tuple of two Arrays : keys in sorted order, and values the corresponding keys. Example Query with Map type: sql SELECT mapPopulateSeries(map(1, 10, 5, 20), 6); Result: text โ”Œโ”€mapPopulateSeries(map(1, 10, 5, 20), 6)โ”€โ” โ”‚ {1:10,2:0,3:0,4:0,5:20,6:0} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Query with mapped arrays: sql SELECT mapPopulateSeries([1,2,4], [11,22,44], 5) AS res, toTypeName(res) AS type; Result: text โ”Œโ”€resโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€typeโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ ([1,2,3,4,5],[11,22,0,44,0]) โ”‚ Tuple(Array(UInt8), Array(UInt8)) โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ mapKeys {#mapkeys} Returns the keys of a given map. This function can be optimized by enabling setting optimize_functions_to_subcolumns . With enabled setting, the function only reads the keys subcolumn instead the whole map. The query SELECT mapKeys(m) FROM table is transformed to SELECT m.keys FROM table . Syntax sql mapKeys(map) Arguments map โ€” Map. Map . Returned value Array containing all keys from the map . Array . Example Query: ```sql CREATE TABLE tab (a Map(String, String)) ENGINE = Memory; INSERT INTO tab VALUES ({'name':'eleven','age':'11'}), ({'number':'twelve','position':'6.0'}); SELECT mapKeys(a) FROM tab; ``` Result: text โ”Œโ”€mapKeys(a)โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ ['name','age'] โ”‚ โ”‚ ['number','position'] โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ mapContains {#mapcontains} Returns if a given key is contained in a given map. Syntax sql mapContains(map, key) Alias: mapContainsKey(map, key) Arguments map โ€” Map. Map . key โ€” Key. Type must match the key type of map . Returned value 1 if map contains key , 0 if not. UInt8 . Example Query: ```sql CREATE TABLE tab (a Map(String, String)) ENGINE = Memory; INSERT INTO tab VALUES ({'name':'eleven','age':'11'}), ({'number':'twelve','position':'6.0'}); SELECT mapContains(a, 'name') FROM tab; ``` Result: text โ”Œโ”€mapContains(a, 'name')โ”€โ” โ”‚ 1 โ”‚ โ”‚ 0 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ mapContainsKeyLike {#mapcontainskeylike} Syntax sql mapContainsKeyLike(map, pattern) Arguments - map โ€” Map. Map . - pattern - String pattern to match. Returned value 1 if map contains key like specified pattern, 0 if not. Example Query: ```sql CREATE TABLE tab (a Map(String, String)) ENGINE = Memory; INSERT INTO tab VALUES ({'abc':'abc','def':'def'}), ({'hij':'hij','klm':'klm'}); SELECT mapContainsKeyLike(a, 'a%') FROM tab; ``` Result:
{"source_file": "tuple-map-functions.md"}
[ 0.09543152898550034, 0.03370734676718712, 0.016024233773350716, -0.0458684042096138, -0.0616561621427536, -0.008543086238205433, 0.07491811364889145, -0.03716041147708893, -0.0555494986474514, -0.010703914798796177, -0.055741406977176666, 0.021850675344467163, 0.04781012237071991, 0.002425...
3f5dfb34-fbf1-4bc6-9c51-1aeef0413a3b
INSERT INTO tab VALUES ({'abc':'abc','def':'def'}), ({'hij':'hij','klm':'klm'}); SELECT mapContainsKeyLike(a, 'a%') FROM tab; ``` Result: text โ”Œโ”€mapContainsKeyLike(a, 'a%')โ”€โ” โ”‚ 1 โ”‚ โ”‚ 0 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ mapExtractKeyLike {#mapextractkeylike} Give a map with string keys and a LIKE pattern, this function returns a map with elements where the key matches the pattern. Syntax sql mapExtractKeyLike(map, pattern) Arguments map โ€” Map. Map . pattern - String pattern to match. Returned value A map containing elements the key matching the specified pattern. If no elements match the pattern, an empty map is returned. Example Query: ```sql CREATE TABLE tab (a Map(String, String)) ENGINE = Memory; INSERT INTO tab VALUES ({'abc':'abc','def':'def'}), ({'hij':'hij','klm':'klm'}); SELECT mapExtractKeyLike(a, 'a%') FROM tab; ``` Result: text โ”Œโ”€mapExtractKeyLike(a, 'a%')โ”€โ” โ”‚ {'abc':'abc'} โ”‚ โ”‚ {} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ mapValues {#mapvalues} Returns the values of a given map. This function can be optimized by enabling setting optimize_functions_to_subcolumns . With enabled setting, the function only reads the values subcolumn instead the whole map. The query SELECT mapValues(m) FROM table is transformed to SELECT m.values FROM table . Syntax sql mapValues(map) Arguments map โ€” Map. Map . Returned value Array containing all the values from map . Array . Example Query: ```sql CREATE TABLE tab (a Map(String, String)) ENGINE = Memory; INSERT INTO tab VALUES ({'name':'eleven','age':'11'}), ({'number':'twelve','position':'6.0'}); SELECT mapValues(a) FROM tab; ``` Result: text โ”Œโ”€mapValues(a)โ”€โ”€โ”€โ”€โ”€โ” โ”‚ ['eleven','11'] โ”‚ โ”‚ ['twelve','6.0'] โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ mapContainsValue {#mapcontainsvalue} Returns if a given key is contained in a given map. Syntax sql mapContainsValue(map, value) Alias: mapContainsValue(map, value) Arguments map โ€” Map. Map . value โ€” Value. Type must match the value type of map . Returned value 1 if map contains value , 0 if not. UInt8 . Example Query: ```sql CREATE TABLE tab (a Map(String, String)) ENGINE = Memory; INSERT INTO tab VALUES ({'name':'eleven','age':'11'}), ({'number':'twelve','position':'6.0'}); SELECT mapContainsValue(a, '11') FROM tab; ``` Result: text โ”Œโ”€mapContainsValue(a, '11')โ”€โ” โ”‚ 1 โ”‚ โ”‚ 0 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ mapContainsValueLike {#mapcontainsvaluelike} Syntax sql mapContainsValueLike(map, pattern) Arguments - map โ€” Map. Map . - pattern - String pattern to match. Returned value 1 if map contains value like specified pattern, 0 if not. Example Query: ```sql CREATE TABLE tab (a Map(String, String)) ENGINE = Memory;
{"source_file": "tuple-map-functions.md"}
[ 0.04851106181740761, 0.011581397615373135, 0.03045625053346157, 0.0063859266228973866, -0.1279931515455246, 0.005395405925810337, 0.10791503638029099, -0.02381223440170288, -0.028640521690249443, 0.017232714220881462, 0.08092949539422989, -0.06221179664134979, 0.09199203550815582, -0.06203...
f161d35c-3e7e-4470-9acc-60721d5c024b
Returned value 1 if map contains value like specified pattern, 0 if not. Example Query: ```sql CREATE TABLE tab (a Map(String, String)) ENGINE = Memory; INSERT INTO tab VALUES ({'abc':'abc','def':'def'}), ({'hij':'hij','klm':'klm'}); SELECT mapContainsValueLike(a, 'a%') FROM tab; ``` Result: text โ”Œโ”€mapContainsVโ‹ฏke(a, 'a%')โ”€โ” โ”‚ 1 โ”‚ โ”‚ 0 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ mapExtractValueLike {#mapextractvaluelike} Give a map with string values and a LIKE pattern, this function returns a map with elements where the value matches the pattern. Syntax sql mapExtractValueLike(map, pattern) Arguments map โ€” Map. Map . pattern - String pattern to match. Returned value A map containing elements the value matching the specified pattern. If no elements match the pattern, an empty map is returned. Example Query: ```sql CREATE TABLE tab (a Map(String, String)) ENGINE = Memory; INSERT INTO tab VALUES ({'abc':'abc','def':'def'}), ({'hij':'hij','klm':'klm'}); SELECT mapExtractValueLike(a, 'a%') FROM tab; ``` Result: text โ”Œโ”€mapExtractValueLike(a, 'a%')โ”€โ” โ”‚ {'abc':'abc'} โ”‚ โ”‚ {} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ mapApply {#mapapply} Applies a function to each element of a map. Syntax sql mapApply(func, map) Arguments func โ€” Lambda function . map โ€” Map . Returned value Returns a map obtained from the original map by application of func(map1[i], ..., mapN[i]) for each element. Example Query: sql SELECT mapApply((k, v) -> (k, v * 10), _map) AS r FROM ( SELECT map('key1', number, 'key2', number * 2) AS _map FROM numbers(3) ) Result: text โ”Œโ”€rโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ {'key1':0,'key2':0} โ”‚ โ”‚ {'key1':10,'key2':20} โ”‚ โ”‚ {'key1':20,'key2':40} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ mapFilter {#mapfilter} Filters a map by applying a function to each map element. Syntax sql mapFilter(func, map) Arguments func - Lambda function . map โ€” Map . Returned value Returns a map containing only the elements in map for which func(map1[i], ..., mapN[i]) returns something other than 0. Example Query: sql SELECT mapFilter((k, v) -> ((v % 2) = 0), _map) AS r FROM ( SELECT map('key1', number, 'key2', number * 2) AS _map FROM numbers(3) ) Result: text โ”Œโ”€rโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ {'key1':0,'key2':0} โ”‚ โ”‚ {'key2':2} โ”‚ โ”‚ {'key1':2,'key2':4} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ mapUpdate {#mapupdate} Syntax sql mapUpdate(map1, map2) Arguments map1 Map . map2 Map . Returned value Returns a map1 with values updated of values for the corresponding keys in map2. Example Query: sql SELECT mapUpdate(map('key1', 0, 'key3', 0), map('key1', 10, 'key2', 10)) AS map; Result: text โ”Œโ”€mapโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ {'key3':0,'key1':10,'key2':10} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ mapConcat {#mapconcat}
{"source_file": "tuple-map-functions.md"}
[ 0.05953338369727135, 0.029257094487547874, 0.018787141889333725, 0.013296307064592838, -0.09690392017364502, -0.009721583686769009, 0.1177404448390007, -0.003480274695903063, -0.0370279997587204, 0.007667591329663992, 0.06654628366231918, -0.09181926399469376, 0.05680422857403755, -0.05327...
b62b96f0-0967-4171-96bf-94bf652f54ed
Result: text โ”Œโ”€mapโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ {'key3':0,'key1':10,'key2':10} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ mapConcat {#mapconcat} Concatenates multiple maps based on the equality of their keys. If elements with the same key exist in more than one input map, all elements are added to the result map, but only the first one is accessible via operator [] Syntax sql mapConcat(maps) Arguments maps โ€“ Arbitrarily many Maps . Returned value Returns a map with concatenated maps passed as arguments. Examples Query: sql SELECT mapConcat(map('key1', 1, 'key3', 3), map('key2', 2)) AS map; Result: text โ”Œโ”€mapโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ {'key1':1,'key3':3,'key2':2} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Query: sql SELECT mapConcat(map('key1', 1, 'key2', 2), map('key1', 3)) AS map, map['key1']; Result: text โ”Œโ”€mapโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€elemโ”€โ” โ”‚ {'key1':1,'key2':2,'key1':3} โ”‚ 1 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”˜ mapExists([func,], map) {#mapexistsfunc-map} Returns 1 if at least one key-value pair in map exists for which func(key, value) returns something other than 0. Otherwise, it returns 0. :::note mapExists is a higher-order function . You can pass a lambda function to it as the first argument. ::: Example Query: sql SELECT mapExists((k, v) -> (v = 1), map('k1', 1, 'k2', 2)) AS res Result: response โ”Œโ”€resโ”€โ” โ”‚ 1 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”˜ mapAll([func,] map) {#mapallfunc-map} Returns 1 if func(key, value) returns something other than 0 for all key-value pairs in map . Otherwise, it returns 0. :::note Note that the mapAll is a higher-order function . You can pass a lambda function to it as the first argument. ::: Example Query: sql SELECT mapAll((k, v) -> (v = 1), map('k1', 1, 'k2', 2)) AS res Result: response โ”Œโ”€resโ”€โ” โ”‚ 0 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”˜ mapSort([func,], map) {#mapsortfunc-map} Sorts the elements of a map in ascending order. If the func function is specified, the sorting order is determined by the result of the func function applied to the keys and values of the map. Examples sql SELECT mapSort(map('key2', 2, 'key3', 1, 'key1', 3)) AS map; text โ”Œโ”€mapโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ {'key1':3,'key2':2,'key3':1} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ sql SELECT mapSort((k, v) -> v, map('key2', 2, 'key3', 1, 'key1', 3)) AS map; text โ”Œโ”€mapโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ {'key3':1,'key2':2,'key1':3} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ For more details see the reference for arraySort function. mapPartialSort {#mappartialsort} Sorts the elements of a map in ascending order with additional limit argument allowing partial sorting. If the func function is specified, the sorting order is determined by the result of the func function applied to the keys and values of the map. Syntax sql mapPartialSort([func,] limit, map) Arguments func โ€“ Optional function to apply to the keys and values of the map. Lambda function .
{"source_file": "tuple-map-functions.md"}
[ 0.06938417255878448, -0.02405044250190258, 0.06984133273363113, -0.01020691730082035, -0.06842996925115585, -0.000664091669023037, 0.09096751362085342, -0.03987792879343033, -0.03396991267800331, -0.01527873519808054, 0.07550781965255737, 0.003286849008873105, 0.07359714061021805, -0.08632...
5913dbb8-2cd9-4ec2-9b31-cd38681fbc93
Syntax sql mapPartialSort([func,] limit, map) Arguments func โ€“ Optional function to apply to the keys and values of the map. Lambda function . limit โ€“ Elements in range [1..limit] are sorted. (U)Int . map โ€“ Map to sort. Map . Returned value Partially sorted map. Map . Example sql SELECT mapPartialSort((k, v) -> v, 2, map('k1', 3, 'k2', 1, 'k3', 2)); text โ”Œโ”€mapPartialSort(lambda(tuple(k, v), v), 2, map('k1', 3, 'k2', 1, 'k3', 2))โ”€โ” โ”‚ {'k2':1,'k3':2,'k1':3} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ mapReverseSort([func,], map) {#mapreversesortfunc-map} Sorts the elements of a map in descending order. If the func function is specified, the sorting order is determined by the result of the func function applied to the keys and values of the map. Examples sql SELECT mapReverseSort(map('key2', 2, 'key3', 1, 'key1', 3)) AS map; text โ”Œโ”€mapโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ {'key3':1,'key2':2,'key1':3} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ sql SELECT mapReverseSort((k, v) -> v, map('key2', 2, 'key3', 1, 'key1', 3)) AS map; text โ”Œโ”€mapโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ {'key1':3,'key2':2,'key3':1} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ For more details see function arrayReverseSort . mapPartialReverseSort {#mappartialreversesort} Sorts the elements of a map in descending order with additional limit argument allowing partial sorting. If the func function is specified, the sorting order is determined by the result of the func function applied to the keys and values of the map. Syntax sql mapPartialReverseSort([func,] limit, map) Arguments func โ€“ Optional function to apply to the keys and values of the map. Lambda function . limit โ€“ Elements in range [1..limit] are sorted. (U)Int . map โ€“ Map to sort. Map . Returned value Partially sorted map. Map . Example sql SELECT mapPartialReverseSort((k, v) -> v, 2, map('k1', 3, 'k2', 1, 'k3', 2)); text โ”Œโ”€mapPartialReverseSort(lambda(tuple(k, v), v), 2, map('k1', 3, 'k2', 1, 'k3', 2))โ”€โ” โ”‚ {'k1':3,'k3':2,'k2':1} โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
{"source_file": "tuple-map-functions.md"}
[ 0.06363070011138916, -0.00777852488681674, 0.06404333561658859, -0.06110365688800812, -0.05329585820436478, -0.025099126622080803, 0.05327514931559563, -0.009026862680912018, -0.05913933739066124, 0.07958463579416275, 0.03299028426408768, 0.031967584043741226, -0.0026148229371756315, -0.02...
700bc6bb-3166-4ce1-b25b-0318ffb943d0
description: 'Documentation for Functions for Working with Dictionaries' sidebar_label: 'Dictionaries' slug: /sql-reference/functions/ext-dict-functions title: 'Functions for Working with Dictionaries' doc_type: 'reference' Functions for Working with Dictionaries :::note For dictionaries created with DDL queries , the dict_name parameter must be fully specified, like <database>.<dict_name> . Otherwise, the current database is used. ::: For information on connecting and configuring dictionaries, see Dictionaries . dictGet, dictGetOrDefault, dictGetOrNull {#dictget-dictgetordefault-dictgetornull} Retrieves values from a dictionary. sql dictGet('dict_name', attr_names, id_expr) dictGetOrDefault('dict_name', attr_names, id_expr, default_value_expr) dictGetOrNull('dict_name', attr_name, id_expr) Arguments dict_name โ€” Name of the dictionary. String literal . attr_names โ€” Name of the column of the dictionary, String literal , or tuple of column names, Tuple ( String literal . id_expr โ€” Key value. Expression returning dictionary key-type value or Tuple -type value depending on the dictionary configuration. default_value_expr โ€” Values returned if the dictionary does not contain a row with the id_expr key. Expression or Tuple ( Expression ), returning the value (or values) in the data types configured for the attr_names attribute. Returned value If ClickHouse parses the attribute successfully in the attribute's data type , functions return the value of the dictionary attribute that corresponds to id_expr . If there is no the key, corresponding to id_expr , in the dictionary, then: - `dictGet` returns the content of the `<null_value>` element specified for the attribute in the dictionary configuration. - `dictGetOrDefault` returns the value passed as the `default_value_expr` parameter. - `dictGetOrNull` returns `NULL` in case key was not found in dictionary. ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type. Example for simple key dictionary Create a text file ext-dict-test.csv containing the following: text 1,1 2,2 The first column is id , the second column is c1 . Configure the dictionary: xml <clickhouse> <dictionary> <name>ext-dict-test</name> <source> <file> <path>/path-to/ext-dict-test.csv</path> <format>CSV</format> </file> </source> <layout> <flat /> </layout> <structure> <id> <name>id</name> </id> <attribute> <name>c1</name> <type>UInt32</type> <null_value></null_value> </attribute> </structure> <lifetime>0</lifetime> </dictionary> </clickhouse> Perform the query:
{"source_file": "ext-dict-functions.md"}
[ -0.016703831031918526, -0.014580406248569489, -0.08432993292808533, 0.006218149326741695, -0.08719804883003235, -0.06172670051455498, 0.09186474233865738, 0.04871220141649246, -0.10244531184434891, -0.0427074059844017, 0.05583468824625015, -0.04284672066569328, 0.05096141993999481, -0.0799...
a8738fd8-2a8b-45b3-97bc-8fe10b039937
Perform the query: sql SELECT dictGetOrDefault('ext-dict-test', 'c1', number + 1, toUInt32(number * 10)) AS val, toTypeName(val) AS type FROM system.numbers LIMIT 3; text โ”Œโ”€valโ”€โ”ฌโ”€typeโ”€โ”€โ”€โ” โ”‚ 1 โ”‚ UInt32 โ”‚ โ”‚ 2 โ”‚ UInt32 โ”‚ โ”‚ 20 โ”‚ UInt32 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Example for complex key dictionary Create a text file ext-dict-mult.csv containing the following: text 1,1,'1' 2,2,'2' 3,3,'3' The first column is id , the second is c1 , the third is c2 . Configure the dictionary: xml <clickhouse> <dictionary> <name>ext-dict-mult</name> <source> <file> <path>/path-to/ext-dict-mult.csv</path> <format>CSV</format> </file> </source> <layout> <flat /> </layout> <structure> <id> <name>id</name> </id> <attribute> <name>c1</name> <type>UInt32</type> <null_value></null_value> </attribute> <attribute> <name>c2</name> <type>String</type> <null_value></null_value> </attribute> </structure> <lifetime>0</lifetime> </dictionary> </clickhouse> Perform the query: sql SELECT dictGet('ext-dict-mult', ('c1','c2'), number + 1) AS val, toTypeName(val) AS type FROM system.numbers LIMIT 3; text โ”Œโ”€valโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€typeโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ (1,'1') โ”‚ Tuple(UInt8, String) โ”‚ โ”‚ (2,'2') โ”‚ Tuple(UInt8, String) โ”‚ โ”‚ (3,'3') โ”‚ Tuple(UInt8, String) โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Example for range key dictionary Input table: ```sql CREATE TABLE range_key_dictionary_source_table ( key UInt64, start_date Date, end_date Date, value String, value_nullable Nullable(String) ) ENGINE = TinyLog(); INSERT INTO range_key_dictionary_source_table VALUES(1, toDate('2019-05-20'), toDate('2019-05-20'), 'First', 'First'); INSERT INTO range_key_dictionary_source_table VALUES(2, toDate('2019-05-20'), toDate('2019-05-20'), 'Second', NULL); INSERT INTO range_key_dictionary_source_table VALUES(3, toDate('2019-05-20'), toDate('2019-05-20'), 'Third', 'Third'); ``` Create the dictionary: sql CREATE DICTIONARY range_key_dictionary ( key UInt64, start_date Date, end_date Date, value String, value_nullable Nullable(String) ) PRIMARY KEY key SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() TABLE 'range_key_dictionary_source_table')) LIFETIME(MIN 1 MAX 1000) LAYOUT(RANGE_HASHED()) RANGE(MIN start_date MAX end_date); Perform the query:
{"source_file": "ext-dict-functions.md"}
[ 0.004385502077639103, 0.049856461584568024, -0.10542737692594528, 0.004064422100782394, -0.020338786765933037, -0.06363154202699661, 0.12773706018924713, 0.07065024971961975, -0.030039021745324135, 0.012715978547930717, 0.05100042000412941, -0.06453239172697067, 0.09468836337327957, -0.091...
20c1a285-b322-42c6-af91-f72a3909ef9f
Perform the query: sql SELECT (number, toDate('2019-05-20')), dictHas('range_key_dictionary', number, toDate('2019-05-20')), dictGetOrNull('range_key_dictionary', 'value', number, toDate('2019-05-20')), dictGetOrNull('range_key_dictionary', 'value_nullable', number, toDate('2019-05-20')), dictGetOrNull('range_key_dictionary', ('value', 'value_nullable'), number, toDate('2019-05-20')) FROM system.numbers LIMIT 5 FORMAT TabSeparated; Result: text (0,'2019-05-20') 0 \N \N (NULL,NULL) (1,'2019-05-20') 1 First First ('First','First') (2,'2019-05-20') 1 Second \N ('Second',NULL) (3,'2019-05-20') 1 Third Third ('Third','Third') (4,'2019-05-20') 0 \N \N (NULL,NULL) See Also Dictionaries dictHas {#dicthas} Checks whether a key is present in a dictionary. sql dictHas('dict_name', id_expr) Arguments dict_name โ€” Name of the dictionary. String literal . id_expr โ€” Key value. Expression returning dictionary key-type value or Tuple -type value depending on the dictionary configuration. Returned value 0, if there is no key. UInt8 . 1, if there is a key. UInt8 . dictGetHierarchy {#dictgethierarchy} Creates an array, containing all the parents of a key in the hierarchical dictionary . Syntax sql dictGetHierarchy('dict_name', key) Arguments dict_name โ€” Name of the dictionary. String literal . key โ€” Key value. Expression returning a UInt64 -type value. Returned value Parents for the key. Array(UInt64) . dictIsIn {#dictisin} Checks the ancestor of a key through the whole hierarchical chain in the dictionary. sql dictIsIn('dict_name', child_id_expr, ancestor_id_expr) Arguments dict_name โ€” Name of the dictionary. String literal . child_id_expr โ€” Key to be checked. Expression returning a UInt64 -type value. ancestor_id_expr โ€” Alleged ancestor of the child_id_expr key. Expression returning a UInt64 -type value. Returned value 0, if child_id_expr is not a child of ancestor_id_expr . UInt8 . 1, if child_id_expr is a child of ancestor_id_expr or if child_id_expr is an ancestor_id_expr . UInt8 . dictGetChildren {#dictgetchildren} Returns first-level children as an array of indexes. It is the inverse transformation for dictGetHierarchy . Syntax sql dictGetChildren(dict_name, key) Arguments dict_name โ€” Name of the dictionary. String literal . key โ€” Key value. Expression returning a UInt64 -type value. Returned values First-level descendants for the key. Array ( UInt64 ). Example Consider the hierarchic dictionary: text โ”Œโ”€idโ”€โ”ฌโ”€parent_idโ”€โ” โ”‚ 1 โ”‚ 0 โ”‚ โ”‚ 2 โ”‚ 1 โ”‚ โ”‚ 3 โ”‚ 1 โ”‚ โ”‚ 4 โ”‚ 2 โ”‚ โ””โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ First-level children: sql SELECT dictGetChildren('hierarchy_flat_dictionary', number) FROM system.numbers LIMIT 4;
{"source_file": "ext-dict-functions.md"}
[ 0.056528493762016296, 0.01689242571592331, -0.027085838839411736, -0.02836545556783676, -0.10156571120023727, 0.0405011810362339, 0.04473169893026352, 0.051002249121665955, -0.06794287264347076, 0.03677883744239807, 0.05722688138484955, -0.01983119361102581, 0.07168370485305786, -0.0541735...
3d5f8261-e638-4661-8b47-91ee0be9c7f1
First-level children: sql SELECT dictGetChildren('hierarchy_flat_dictionary', number) FROM system.numbers LIMIT 4; text โ”Œโ”€dictGetChildren('hierarchy_flat_dictionary', number)โ”€โ” โ”‚ [1] โ”‚ โ”‚ [2,3] โ”‚ โ”‚ [4] โ”‚ โ”‚ [] โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ dictGetDescendant {#dictgetdescendant} Returns all descendants as if dictGetChildren function was applied level times recursively. Syntax sql dictGetDescendants(dict_name, key, level) Arguments dict_name โ€” Name of the dictionary. String literal . key โ€” Key value. Expression returning a UInt64 -type value. level โ€” Hierarchy level. If level = 0 returns all descendants to the end. UInt8 . Returned values Descendants for the key. Array ( UInt64 ). Example Consider the hierarchic dictionary: text โ”Œโ”€idโ”€โ”ฌโ”€parent_idโ”€โ” โ”‚ 1 โ”‚ 0 โ”‚ โ”‚ 2 โ”‚ 1 โ”‚ โ”‚ 3 โ”‚ 1 โ”‚ โ”‚ 4 โ”‚ 2 โ”‚ โ””โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ All descendants: sql SELECT dictGetDescendants('hierarchy_flat_dictionary', number) FROM system.numbers LIMIT 4; text โ”Œโ”€dictGetDescendants('hierarchy_flat_dictionary', number)โ”€โ” โ”‚ [1,2,3,4] โ”‚ โ”‚ [2,3,4] โ”‚ โ”‚ [4] โ”‚ โ”‚ [] โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ First-level descendants: sql SELECT dictGetDescendants('hierarchy_flat_dictionary', number, 1) FROM system.numbers LIMIT 4; text โ”Œโ”€dictGetDescendants('hierarchy_flat_dictionary', number, 1)โ”€โ” โ”‚ [1] โ”‚ โ”‚ [2,3] โ”‚ โ”‚ [4] โ”‚ โ”‚ [] โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ dictGetAll {#dictgetall} Retrieves the attribute values of all nodes that matched each key in a regular expression tree dictionary . Besides returning values of type Array(T) instead of T , this function behaves similarly to dictGet . Syntax sql dictGetAll('dict_name', attr_names, id_expr[, limit]) Arguments dict_name โ€” Name of the dictionary. String literal . attr_names โ€” Name of the column of the dictionary, String literal , or tuple of column names, Tuple ( String literal ). id_expr โ€” Key value. Expression returning array of dictionary key-type value or Tuple -type value depending on the dictionary configuration.
{"source_file": "ext-dict-functions.md"}
[ -0.011556187644600868, -0.03597201406955719, 0.021325459703803062, -0.01643506810069084, -0.045322615653276443, -0.1030673161149025, 0.008793942630290985, 0.021529365330934525, -0.036128293722867966, 0.03755176439881325, 0.021163126453757286, -0.03412669897079468, 0.017134645953774452, -0....
d0ac8b4b-b6de-4113-8a65-54783b191877
id_expr โ€” Key value. Expression returning array of dictionary key-type value or Tuple -type value depending on the dictionary configuration. limit - Maximum length for each value array returned. When truncating, child nodes are given precedence over parent nodes, and otherwise the defined list order for the regexp tree dictionary is respected. If unspecified, array length is unlimited. Returned value If ClickHouse parses the attribute successfully in the attribute's data type as defined in the dictionary, returns an array of dictionary attribute values that correspond to id_expr for each attribute specified by attr_names . If there is no key corresponding to id_expr in the dictionary, then an empty array is returned. ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type. Example Consider the following regexp tree dictionary: sql CREATE DICTIONARY regexp_dict ( regexp String, tag String ) PRIMARY KEY(regexp) SOURCE(YAMLRegExpTree(PATH '/var/lib/clickhouse/user_files/regexp_tree.yaml')) LAYOUT(regexp_tree) ... ```yaml /var/lib/clickhouse/user_files/regexp_tree.yaml regexp: 'foo' tag: 'foo_attr' regexp: 'bar' tag: 'bar_attr' regexp: 'baz' tag: 'baz_attr' ``` Get all matching values: sql SELECT dictGetAll('regexp_dict', 'tag', 'foobarbaz'); text โ”Œโ”€dictGetAll('regexp_dict', 'tag', 'foobarbaz')โ”€โ” โ”‚ ['foo_attr','bar_attr','baz_attr'] โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Get up to 2 matching values: sql SELECT dictGetAll('regexp_dict', 'tag', 'foobarbaz', 2); text โ”Œโ”€dictGetAll('regexp_dict', 'tag', 'foobarbaz', 2)โ”€โ” โ”‚ ['foo_attr','bar_attr'] โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Other Functions {#other-functions} ClickHouse supports specialized functions that convert dictionary attribute values to a specific data type regardless of the dictionary configuration. Functions: dictGetInt8 , dictGetInt16 , dictGetInt32 , dictGetInt64 dictGetUInt8 , dictGetUInt16 , dictGetUInt32 , dictGetUInt64 dictGetFloat32 , dictGetFloat64 dictGetDate dictGetDateTime dictGetUUID dictGetString dictGetIPv4 , dictGetIPv6 All these functions have the OrDefault modification. For example, dictGetDateOrDefault . Syntax: sql dictGet[Type]('dict_name', 'attr_name', id_expr) dictGet[Type]OrDefault('dict_name', 'attr_name', id_expr, default_value_expr) Arguments dict_name โ€” Name of the dictionary. String literal . attr_name โ€” Name of the column of the dictionary. String literal . id_expr โ€” Key value. Expression returning a UInt64 or Tuple -type value depending on the dictionary configuration. default_value_expr โ€” Value returned if the dictionary does not contain a row with the id_expr key. Expression returning the value in the data type configured for the attr_name attribute.
{"source_file": "ext-dict-functions.md"}
[ -0.01363968662917614, 0.02142229862511158, -0.01845317892730236, 0.020346995443105698, 0.028897875919938087, -0.12108352035284042, 0.11309349536895752, -0.024098385125398636, -0.010476063005626202, -0.04473277926445007, 0.05295158550143242, 0.019486790522933006, 0.04057437926530838, -0.074...
2c0a7891-3773-42a2-9ada-5fdcb28ef035
default_value_expr โ€” Value returned if the dictionary does not contain a row with the id_expr key. Expression returning the value in the data type configured for the attr_name attribute. Returned value If ClickHouse parses the attribute successfully in the attribute's data type , functions return the value of the dictionary attribute that corresponds to id_expr . If there is no requested id_expr in the dictionary then: - `dictGet[Type]` returns the content of the `<null_value>` element specified for the attribute in the dictionary configuration. - `dictGet[Type]OrDefault` returns the value passed as the `default_value_expr` parameter. ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type. Example dictionaries {#example-dictionary} The examples in this section make use of the following dictionaries. You can create them in ClickHouse to run the examples for the functions described below. Example dictionary for dictGet\ and dictGet\ OrDefault functions ```sql -- Create table with all the required data types CREATE TABLE all_types_test ( `id` UInt32, -- String type `String_value` String, -- Unsigned integer types `UInt8_value` UInt8, `UInt16_value` UInt16, `UInt32_value` UInt32, `UInt64_value` UInt64, -- Signed integer types `Int8_value` Int8, `Int16_value` Int16, `Int32_value` Int32, `Int64_value` Int64, -- Floating point types `Float32_value` Float32, `Float64_value` Float64, -- Date/time types `Date_value` Date, `DateTime_value` DateTime, -- Network types `IPv4_value` IPv4, `IPv6_value` IPv6, -- UUID type `UUID_value` UUID ) ENGINE = MergeTree() ORDER BY id; ``` ```sql -- Insert test data INSERT INTO all_types_test VALUES ( 1, -- id 'ClickHouse', -- String 100, -- UInt8 5000, -- UInt16 1000000, -- UInt32 9223372036854775807, -- UInt64 -100, -- Int8 -5000, -- Int16 -1000000, -- Int32 -9223372036854775808, -- Int64 123.45, -- Float32 987654.123456, -- Float64 '2024-01-15', -- Date '2024-01-15 10:30:00', -- DateTime '192.168.1.1', -- IPv4 '2001:db8::1', -- IPv6 '550e8400-e29b-41d4-a716-446655440000' -- UUID ) ```
{"source_file": "ext-dict-functions.md"}
[ -0.0393059104681015, 0.011418899521231651, -0.06389938294887543, 0.014585528522729874, -0.02192636765539646, -0.12724435329437256, 0.09696991741657257, 0.0007674309890717268, -0.04068334028124809, -0.019427936524152756, 0.08854540437459946, -0.06201138719916344, 0.03660574555397034, -0.018...
291ec1ee-3b2b-4365-9d2e-d6e8a8511ecc
```sql -- Create dictionary CREATE DICTIONARY all_types_dict ( id UInt32, String_value String, UInt8_value UInt8, UInt16_value UInt16, UInt32_value UInt32, UInt64_value UInt64, Int8_value Int8, Int16_value Int16, Int32_value Int32, Int64_value Int64, Float32_value Float32, Float64_value Float64, Date_value Date, DateTime_value DateTime, IPv4_value IPv4, IPv6_value IPv6, UUID_value UUID ) PRIMARY KEY id SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' TABLE 'all_types_test' DB 'default')) LAYOUT(HASHED()) LIFETIME(MIN 300 MAX 600); ``` Example dictionary for dictGetAll Create a table to store the data for the regexp tree dictionary: ```sql CREATE TABLE regexp_os( id UInt64, parent_id UInt64, regexp String, keys Array(String), values Array(String) ) ENGINE = Memory; ``` Insert data into the table: ```sql INSERT INTO regexp_os SELECT * FROM s3( 'https://datasets-documentation.s3.eu-west-3.amazonaws.com/' || 'user_agent_regex/regexp_os.csv' ); ``` Create the regexp tree dictionary: ```sql CREATE DICTIONARY regexp_tree ( regexp String, os_replacement String DEFAULT 'Other', os_v1_replacement String DEFAULT '0', os_v2_replacement String DEFAULT '0', os_v3_replacement String DEFAULT '0', os_v4_replacement String DEFAULT '0' ) PRIMARY KEY regexp SOURCE(CLICKHOUSE(TABLE 'regexp_os')) LIFETIME(MIN 0 MAX 0) LAYOUT(REGEXP_TREE); ``` Example range key dictionary Create the input table: ```sql CREATE TABLE range_key_dictionary_source_table ( key UInt64, start_date Date, end_date Date, value String, value_nullable Nullable(String) ) ENGINE = TinyLog(); ``` Insert the data into the input table: ```sql INSERT INTO range_key_dictionary_source_table VALUES(1, toDate('2019-05-20'), toDate('2019-05-20'), 'First', 'First'); INSERT INTO range_key_dictionary_source_table VALUES(2, toDate('2019-05-20'), toDate('2019-05-20'), 'Second', NULL); INSERT INTO range_key_dictionary_source_table VALUES(3, toDate('2019-05-20'), toDate('2019-05-20'), 'Third', 'Third'); ``` Create the dictionary: ```sql CREATE DICTIONARY range_key_dictionary ( key UInt64, start_date Date, end_date Date, value String, value_nullable Nullable(String) ) PRIMARY KEY key SOURCE(CLICKHOUSE(HOST 'localhost' PORT tcpPort() TABLE 'range_key_dictionary_source_table')) LIFETIME(MIN 1 MAX 1000) LAYOUT(RANGE_HASHED()) RANGE(MIN start_date MAX end_date); ``` Example complex key dictionary Create the source table: ```sql CREATE TABLE dict_mult_source ( id UInt32, c1 UInt32, c2 String ) ENGINE = Memory; ``` Insert the data into the source table: ```sql INSERT INTO dict_mult_source VALUES (1, 1, '1'), (2, 2, '2'), (3, 3, '3'); ``` Create the dictionary:
{"source_file": "ext-dict-functions.md"}
[ 0.03299611061811447, 0.024731434881687164, -0.09528980404138565, -0.0051855226047337055, -0.06899674981832504, -0.07420285791158676, 0.05986224487423897, 0.01076052337884903, -0.048954129219055176, 0.04725949466228485, 0.059328868985176086, -0.055305756628513336, 0.04465627670288086, -0.06...
af1aff8b-d248-4c49-b52a-79150d2897e0
Insert the data into the source table: ```sql INSERT INTO dict_mult_source VALUES (1, 1, '1'), (2, 2, '2'), (3, 3, '3'); ``` Create the dictionary: ```sql CREATE DICTIONARY ext_dict_mult ( id UInt32, c1 UInt32, c2 String ) PRIMARY KEY id SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' TABLE 'dict_mult_source' DB 'default')) LAYOUT(FLAT()) LIFETIME(MIN 0 MAX 0); ``` Example hierarchical dictionary Create the source table: ```sql CREATE TABLE hierarchy_source ( id UInt64, parent_id UInt64, name String ) ENGINE = Memory; ``` Insert the data into the source table: ```sql INSERT INTO hierarchy_source VALUES (0, 0, 'Root'), (1, 0, 'Level 1 - Node 1'), (2, 1, 'Level 2 - Node 2'), (3, 1, 'Level 2 - Node 3'), (4, 2, 'Level 3 - Node 4'), (5, 2, 'Level 3 - Node 5'), (6, 3, 'Level 3 - Node 6'); -- 0 (Root) -- โ””โ”€โ”€ 1 (Level 1 - Node 1) -- โ”œโ”€โ”€ 2 (Level 2 - Node 2) -- โ”‚ โ”œโ”€โ”€ 4 (Level 3 - Node 4) -- โ”‚ โ””โ”€โ”€ 5 (Level 3 - Node 5) -- โ””โ”€โ”€ 3 (Level 2 - Node 3) -- โ””โ”€โ”€ 6 (Level 3 - Node 6) ``` Create the dictionary: ```sql CREATE DICTIONARY hierarchical_dictionary ( id UInt64, parent_id UInt64 HIERARCHICAL, name String ) PRIMARY KEY id SOURCE(CLICKHOUSE(HOST 'localhost' PORT 9000 USER 'default' TABLE 'hierarchy_source' DB 'default')) LAYOUT(HASHED()) LIFETIME(MIN 300 MAX 600); ```
{"source_file": "ext-dict-functions.md"}
[ 0.0071630836464464664, -0.018935730680823326, -0.04964732378721237, 0.010544355027377605, -0.07636799663305283, -0.13553544878959656, 0.014373349025845528, 0.04740879312157631, -0.06570741534233093, 0.08519075065851212, 0.07545055449008942, -0.10641477257013321, 0.12062583863735199, -0.085...
4866a7cf-5d1f-4914-95c0-2b48402ec48d
description: 'Documentation for Index' sidebar: 'sqlreference' slug: /sql-reference/functions title: 'Landing page for Functions' doc_type: 'landing-page' | Page | Description | |---------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------| | Regular Functions | Functions whose result for each row is independent of all other rows. | | Aggregate Functions | Functions that accumulate a set of values across rows. | | Table Functions | Methods for constructing tables. | | Window Functions | Functions which let you perform calculations across a set of rows that are related to the current row. |
{"source_file": "index.md"}
[ -0.046525344252586365, -0.024452682584524155, -0.01758849248290062, 0.035844750702381134, -0.006460214499384165, 0.05930903181433678, 0.04535980895161629, 0.001868721446953714, -0.00570356659591198, 0.021717870607972145, 0.006175692658871412, -0.014951104298233986, 0.06967499852180481, -0....
1e70e7cd-5a0a-4f88-a147-894f3884b249
description: 'Documentation for Functions for Implementing the IN Operator' sidebar_label: 'IN Operator' slug: /sql-reference/functions/in-functions title: 'Functions for Implementing the IN Operator' doc_type: 'reference' Functions for Implementing the IN Operator in, notIn, globalIn, globalNotIn {#in-notin-globalin-globalnotin} See the section IN operators .
{"source_file": "in-functions.md"}
[ -0.023918068036437035, 0.010351141914725304, -0.014584002085030079, 0.014982877299189568, -0.06262154132127762, -0.007385822478681803, 0.08847739547491074, 0.028793325647711754, -0.0995786190032959, -0.04611048102378845, 0.027737412601709366, -0.017758961766958237, 0.04411204531788826, -0....
d0448996-0b68-4555-aa34-bd8d859021b8
description: 'Documentation for financial functions' sidebar_label: 'Financial' slug: /sql-reference/functions/financial-functions title: 'Financial functions' keywords: ['Financial', 'rate of return', 'net present value'] doc_type: 'reference' Financial functions :::note The documentation below is generated from the system.functions system table ::: financialInternalRateOfReturn {#financialInternalRateOfReturn} Introduced in: v25.7 Calculates the Internal Rate of Return (IRR) for a series of cash flows occurring at regular intervals. IRR is the discount rate at which the Net Present Value (NPV) equals zero. IRR attempts to solve the following equation: $$ \sum_{i=0}^n \frac{cashflow_i}{(1 + irr)^i} = 0 $$ Syntax sql financialInternalRateOfReturn(cashflows[, guess]) Arguments cashflows โ€” Array of cash flows. Each value represents a payment (negative value) or income (positive value). Array(Int8/16/32/64) or Array(Float*) [, guess] โ€” Optional initial guess (constant value) for the internal rate of return (default 0.1). Float* Returned value Returns the internal rate of return or NaN if the calculation cannot converge, input array is empty or has only one element, all cash flows are zero, or other calculation errors occur. Float64 Examples simple_example sql title=Query SELECT financialInternalRateOfReturn([-100, 39, 59, 55, 20]) response title=Response 0.2809484211599611 simple_example_with_guess sql title=Query SELECT financialInternalRateOfReturn([-100, 39, 59, 55, 20], 0.1) response title=Response 0.2809484211599611 financialInternalRateOfReturnExtended {#financialInternalRateOfReturnExtended} Introduced in: v25.7 Calculates the Extended Internal Rate of Return (XIRR) for a series of cash flows occurring at irregular intervals. XIRR is the discount rate at which the net present value (NPV) of all cash flows equals zero. XIRR attempts to solve the following equation (example for ACT_365F ): $$ \sum_{i=0}^n \frac{cashflow_i}{(1 + rate)^{(date_i - date_0)/365}} = 0 $$ Arrays should be sorted by date in ascending order. Dates need to be unique. Syntax sql financialInternalRateOfReturnExtended(cashflow, date [, guess, daycount]) Arguments cashflow โ€” An array of cash flows corresponding to the dates in second param. Array(Int8/16/32/64) or Array(Float*) date โ€” A sorted array of unique dates corresponding to the cash flows. Array(Date) or Array(Date32) [, guess] โ€” Optional. Initial guess (constant value) for the XIRR calculation. Float* [, daycount] โ€” Optional day count convention (default 'ACT_365F'). Supported values: 'ACT_365F' - Actual/365 Fixed: Uses actual number of days between dates divided by 365 'ACT_365_25' - Actual/365.25: Uses actual number of days between dates divided by 365.25 String Returned value Returns the XIRR value. If the calculation cannot be performed, it returns NaN. Float64 Examples
{"source_file": "financial-functions.md"}
[ -0.0535828098654747, 0.006876407656818628, -0.09874052554368973, 0.0492856465280056, -0.010285967960953712, -0.08663105964660645, 0.06213011220097542, 0.04006943106651306, 0.06661880761384964, 0.08164780586957932, 0.024899374693632126, -0.08189085870981216, -0.01829157955944538, -0.0075887...
46748187-5a67-44d4-80d1-1967b0c25885
Returned value Returns the XIRR value. If the calculation cannot be performed, it returns NaN. Float64 Examples simple_example sql title=Query SELECT financialInternalRateOfReturnExtended([-10000, 5750, 4250, 3250], [toDate('2020-01-01'), toDate('2020-03-01'), toDate('2020-10-30'), toDate('2021-02-15')]) response title=Response 0.6342972615260243 simple_example_with_guess sql title=Query SELECT financialInternalRateOfReturnExtended([-10000, 5750, 4250, 3250], [toDate('2020-01-01'), toDate('2020-03-01'), toDate('2020-10-30'), toDate('2021-02-15')], 0.5) response title=Response 0.6342972615260243 simple_example_daycount sql title=Query SELECT round(financialInternalRateOfReturnExtended([100000, -110000], [toDate('2020-01-01'), toDate('2021-01-01')], 0.1, 'ACT_365_25'), 6) AS xirr_365_25 response title=Response 0.099785 financialNetPresentValue {#financialNetPresentValue} Introduced in: v25.7 Calculates the Net Present Value (NPV) of a series of cash flows assuming equal time intervals between each cash flow. Default variant ( start_from_zero = true): $$ \sum_{i=0}^{N-1} \frac{values_i}{(1 + rate)^i} $$ Excel-compatible variant ( start_from_zero = false): $$ \sum_{i=1}^{N} \frac{values_i}{(1 + rate)^i} $$ Syntax sql financialNetPresentValue(rate, cashflows[, start_from_zero]) Arguments rate โ€” The discount rate to apply. Float* cashflows โ€” Array of cash flows. Each value represents a payment (negative value) or income (positive value). Array(Int8/16/32/64) or Array(Float*) [, start_from_zero] โ€” Optional boolean parameter indicating whether to start the NPV calculation from period 0 (true) or period 1 (false, Excel-compatible). Default: true. Bool Returned value Returns the net present value as a Float64 value. Float64 Examples default_calculation sql title=Query SELECT financialNetPresentValue(0.08, [-40000., 5000., 8000., 12000., 30000.]) response title=Response 3065.2226681795255 excel_compatible_calculation sql title=Query SELECT financialNetPresentValue(0.08, [-40000., 5000., 8000., 12000., 30000.], false) response title=Response 2838.1691372032656 financialNetPresentValueExtended {#financialNetPresentValueExtended} Introduced in: v25.7 Calculates the Extended Net Present Value (XNPV) for a series of cash flows occurring at irregular intervals. XNPV considers the specific timing of each cash flow when calculating present value. XNPV equation for ACT_365F : $$ XNPV=\sum_{i=1}^n \frac{cashflow_i}{(1 + rate)^{(date_i - date_0)/365}} $$ Arrays should be sorted by date in ascending order. Dates need to be unique. Syntax sql financialNetPresentValueExtended(rate, cashflows, dates[, daycount]) Arguments rate โ€” The discount rate to apply. Float*
{"source_file": "financial-functions.md"}
[ -0.024836348369717598, 0.01766958460211754, -0.02725447528064251, 0.07056910544633865, -0.003143188776448369, -0.09519591182470322, 0.07123827189207077, 0.02650454267859459, 0.040195614099502563, 0.03205989673733711, 0.059601251035928726, -0.1559818685054779, -0.04544336721301079, -0.03447...
28763828-6cb2-4ab7-914b-d40f988cd0c9
Syntax sql financialNetPresentValueExtended(rate, cashflows, dates[, daycount]) Arguments rate โ€” The discount rate to apply. Float* cashflows โ€” Array of cash flows. Each value represents a payment (negative value) or income (positive value). Must contain at least one positive and one negative value. Array(Int8/16/32/64) or Array(Float*) dates โ€” Array of dates corresponding to each cash flow. Must have the same size as cashflows array. Array(Date) or Array(Date32) [, daycount] โ€” Optional day count convention. Supported values: 'ACT_365F' (default) โ€” Actual/365 Fixed, 'ACT_365_25' โ€” Actual/365.25. String Returned value Returns the net present value as a Float64 value. Float64 Examples Basic usage sql title=Query SELECT financialNetPresentValueExtended(0.1, [-10000., 5750., 4250., 3250.], [toDate('2020-01-01'), toDate('2020-03-01'), toDate('2020-10-30'), toDate('2021-02-15')]) response title=Response 2506.579458169746 Using different day count convention sql title=Query SELECT financialNetPresentValueExtended(0.1, [-10000., 5750., 4250., 3250.], [toDate('2020-01-01'), toDate('2020-03-01'), toDate('2020-10-30'), toDate('2021-02-15')], 'ACT_365_25') response title=Response 2507.067268742502 Related resources {#related-resources} Financial functions in ClickHouse video
{"source_file": "financial-functions.md"}
[ 0.010991252958774567, 0.008975919336080551, -0.08750376850366592, 0.05429405719041824, -0.08064112067222595, -0.0017982623539865017, 0.11663182824850082, 0.004297897685319185, 0.026530291885137558, 0.05507160723209381, 0.037461474537849426, -0.15438058972358704, -0.01441167388111353, 0.032...
880b0dcf-ef65-42e3-9793-3ecb344104a7
description: 'Documentation for Files' sidebar_label: 'Files' slug: /sql-reference/functions/files title: 'Files' doc_type: 'reference' file {#file} Reads a file as string and loads the data into the specified column. The file content is not interpreted. Also see table function file . Syntax sql file(path[, default]) Arguments path โ€” The path of the file relative to user_files_path . Supports wildcards * , ** , ? , {abc,def} and {N..M} where N , M are numbers and 'abc', 'def' are strings. default โ€” The value returned if the file does not exist or cannot be accessed. Supported data types: String and NULL . Example Inserting data from files a.txt and b.txt into a table as strings: sql INSERT INTO table SELECT file('a.txt'), file('b.txt');
{"source_file": "files.md"}
[ 0.011177814565598965, -0.026424314826726913, -0.10719440132379532, 0.060317832976579666, -0.04574881121516228, -0.014348652213811874, 0.08152095228433609, 0.1300063282251358, -0.05413384735584259, 0.022070663049817085, 0.032820045948028564, 0.06456179171800613, 0.07627835124731064, -0.0721...
d764339a-f345-42df-9008-9bfeca37016f
description: 'Documentation for Array Functions' sidebar_label: 'Arrays' slug: /sql-reference/functions/array-functions title: 'Array Functions' doc_type: 'reference' Array functions array {#array} Introduced in: v1.1 Creates an array from the function arguments. The arguments should be constants and have types that share a common supertype. At least one argument must be passed, because otherwise it isn't clear which type of array to create. This means that you can't use this function to create an empty array. To do so, use the emptyArray* function. Use the [ ] operator for the same functionality. Syntax sql array(x1 [, x2, ..., xN]) Arguments x1 โ€” Constant value of any type T. If only this argument is provided, the array will be of type T. - [, x2, ..., xN] โ€” Additional N constant values sharing a common supertype with x1 Returned value Returns an array, where 'T' is the smallest common type out of the passed arguments. Array(T) Examples Valid usage sql title=Query SELECT array(toInt32(1), toUInt16(2), toInt8(3)) AS a, toTypeName(a) response title=Response โ”Œโ”€aโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€toTypeName(a)โ”€โ” โ”‚ [1,2,3] โ”‚ Array(Int32) โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Invalid usage sql title=Query SELECT array(toInt32(5), toDateTime('1998-06-16'), toInt8(5)) AS a, toTypeName(a) response title=Response Received exception from server (version 25.4.3): Code: 386. DB::Exception: Received from localhost:9000. DB::Exception: There is no supertype for types Int32, DateTime, Int8 ... arrayAUCPR {#arrayAUCPR} Introduced in: v20.4 Calculates the area under the precision-recall (PR) curve. A precision-recall curve is created by plotting precision on the y-axis and recall on the x-axis across all thresholds. The resulting value ranges from 0 to 1, with a higher value indicating better model performance. The PR AUC is particularly useful for imbalanced datasets, providing a clearer comparison of performance compared to ROC AUC on those cases. For more details, please see here , here and here . Syntax sql arrayAUCPR(scores, labels[, partial_offsets]) Aliases : arrayPRAUC Arguments cores โ€” Scores prediction model gives. Array((U)Int*) or Array(Float*) labels โ€” Labels of samples, usually 1 for positive sample and 0 for negative sample. Array((U)Int*) or Array(Enum) partial_offsets โ€” Optional. An Array(T) of three non-negative integers for calculating a partial area under the PR curve (equivalent to a vertical band of the PR space) instead of the whole AUC. This option is useful for distributed computation of the PR AUC. The array must contain the following elements [ higher_partitions_tp , higher_partitions_fp , total_positives ]. higher_partitions_tp : The number of positive labels in the higher-scored partitions. higher_partitions_fp : The number of negative labels in the higher-scored partitions. total_positives : The total number of positive samples in the entire dataset.
{"source_file": "array-functions.md"}
[ 0.0633634701371193, -0.026371899992227554, -0.02996951900422573, 0.025394875556230545, -0.07585912197828293, -0.03736783564090729, 0.11947458982467651, 0.009412389248609543, -0.06414654105901718, -0.04412249103188515, -0.03103124350309372, -0.011100773699581623, 0.040827877819538116, -0.06...
0a85d3a1-4d4f-44ff-a5ff-73dad0fc5b45
higher_partitions_fp : The number of negative labels in the higher-scored partitions. total_positives : The total number of positive samples in the entire dataset. ::::note When arr_partial_offsets is used, the arr_scores and arr_labels should be only a partition of the entire dataset, containing an interval of scores. The dataset should be divided into contiguous partitions, where each partition contains the subset of the data whose scores fall within a specific range. For example: - One partition could contain all scores in the range [0, 0.5). - Another partition could contain scores in the range [0.5, 1.0]. :::: Returned value Returns area under the precision-recall (PR) curve. Float64 Examples Usage example sql title=Query SELECT arrayAUCPR([0.1, 0.4, 0.35, 0.8], [0, 0, 1, 1]); response title=Response โ”Œโ”€arrayAUCPR([0.1, 0.4, 0.35, 0.8], [0, 0, 1, 1])โ”€โ” โ”‚ 0.8333333333333333 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ arrayAll {#arrayAll} Introduced in: v1.1 Returns 1 if lambda func(x [, y1, y2, ... yN]) returns true for all elements. Otherwise, it returns 0 . Syntax sql arrayAll(func(x[, y1, ..., yN]), source_arr[, cond1_arr, ... , condN_arr]) Arguments func(x[, y1, ..., yN]) โ€” A lambda function which operates on elements of the source array ( x ) and condition arrays ( y ). Lambda function source_arr โ€” The source array to process. Array(T) cond1_arr, ... โ€” Optional. N condition arrays providing additional arguments to the lambda function. Array(T) Returned value Returns 1 if the lambda function returns true for all elements, 0 otherwise UInt8 Examples All elements match sql title=Query SELECT arrayAll(x, y -> x=y, [1, 2, 3], [1, 2, 3]) response title=Response 1 Not all elements match sql title=Query SELECT arrayAll(x, y -> x=y, [1, 2, 3], [1, 1, 1]) response title=Response 0 arrayAvg {#arrayAvg} Introduced in: v21.1 Returns the average of elements in the source array. If a lambda function func is specified, returns the average of elements of the lambda results. Syntax sql arrayAvg([func(x[, y1, ..., yN])], source_arr[, cond1_arr, ... , condN_arr]) Arguments func(x[, y1, ..., yN]) โ€” Optional. A lambda function which operates on elements of the source array ( x ) and condition arrays ( y ). Lambda function source_arr โ€” The source array to process. Array(T) [, cond1_arr, ... , condN_arr] โ€” Optional. N condition arrays providing additional arguments to the lambda function. Array(T) Returned value Returns the average of elements in the source array, or the average of elements of the lambda results if provided. Float64 Examples Basic example sql title=Query SELECT arrayAvg([1, 2, 3, 4]); response title=Response 2.5 Usage with lambda function sql title=Query SELECT arrayAvg(x, y -> x*y, [2, 3], [2, 3]) AS res; response title=Response 6.5 arrayCompact {#arrayCompact}
{"source_file": "array-functions.md"}
[ -0.008852574042975903, -0.00016008305829018354, -0.07510159909725189, -0.02268165536224842, -0.003489759983494878, -0.017443999648094177, 0.035615283995866776, 0.09561069309711456, 0.036205556243658066, -0.04865902662277222, -0.03797268494963646, -0.02269326150417328, 0.020711101591587067, ...
a73c1056-0df6-4267-8870-02eae4ce65e2
response title=Response 2.5 Usage with lambda function sql title=Query SELECT arrayAvg(x, y -> x*y, [2, 3], [2, 3]) AS res; response title=Response 6.5 arrayCompact {#arrayCompact} Introduced in: v20.1 Removes consecutive duplicate elements from an array, including null values. The order of values in the resulting array is determined by the order in the source array. Syntax sql arrayCompact(arr) Arguments arr โ€” An array to remove duplicates from. Array(T) Returned value Returns an array without duplicate values Array(T) Examples Usage example sql title=Query SELECT arrayCompact([1, 1, nan, nan, 2, 3, 3, 3]); response title=Response [1,nan,2,3] arrayConcat {#arrayConcat} Introduced in: v1.1 Combines arrays passed as arguments. Syntax sql arrayConcat(arr1 [, arr2, ... , arrN]) Arguments arr1 [, arr2, ... , arrN] โ€” N number of arrays to concatenate. Array(T) Returned value Returns a single combined array from the provided array arguments. Array(T) Examples Usage example sql title=Query SELECT arrayConcat([1, 2], [3, 4], [5, 6]) AS res response title=Response [1, 2, 3, 4, 5, 6] arrayCount {#arrayCount} Introduced in: v1.1 Returns the number of elements for which func(arr1[i], ..., arrN[i]) returns true. If func is not specified, it returns the number of non-zero elements in the array. arrayCount is a higher-order function . Syntax sql arrayCount([func, ] arr1, ...) Arguments func โ€” Optional. Function to apply to each element of the array(s). Lambda function arr1, ..., arrN โ€” N arrays. Array(T) Returned value Returns the number of elements for which func returns true. Otherwise, returns the number of non-zero elements in the array. UInt32 Examples Usage example sql title=Query SELECT arrayCount(x -> (x % 2), groupArray(number)) FROM numbers(10) response title=Response 5 arrayCumSum {#arrayCumSum} Introduced in: v1.1 Returns an array of the partial (running) sums of the elements in the source array. If a lambda function is specified, the sum is computed from applying the lambda to the array elements at each position. Syntax sql arrayCumSum([func,] arr1[, arr2, ... , arrN]) Arguments func โ€” Optional. A lambda function to apply to the array elements at each position. Lambda function arr1 โ€” The source array of numeric values. Array(T) [arr2, ..., arrN] โ€” Optional. Additional arrays of the same size, passed as arguments to the lambda function if specified. Array(T) Returned value Returns an array of the partial sums of the elements in the source array. The result type matches the input array's numeric type. Array(T) Examples Basic usage sql title=Query SELECT arrayCumSum([1, 1, 1, 1]) AS res response title=Response [1, 2, 3, 4] With lambda sql title=Query SELECT arrayCumSum(x -> x * 2, [1, 2, 3]) AS res response title=Response [2, 6, 12] arrayCumSumNonNegative {#arrayCumSumNonNegative}
{"source_file": "array-functions.md"}
[ -0.009875958785414696, -0.05482213944196701, -0.02596152387559414, -0.001835880451835692, -0.07956364750862122, -0.07952603697776794, 0.09708735346794128, -0.10459310561418533, 0.019140101969242096, -0.04506077617406845, -0.0061775920912623405, 0.07375524938106537, 0.03626396507024765, -0....
14704e34-27e3-477a-b44b-ecde960da068
With lambda sql title=Query SELECT arrayCumSum(x -> x * 2, [1, 2, 3]) AS res response title=Response [2, 6, 12] arrayCumSumNonNegative {#arrayCumSumNonNegative} Introduced in: v18.12 Returns an array of the partial (running) sums of the elements in the source array, replacing any negative running sum with zero. If a lambda function is specified, the sum is computed from applying the lambda to the array elements at each position. Syntax sql arrayCumSumNonNegative([func,] arr1[, arr2, ... , arrN]) Arguments func โ€” Optional. A lambda function to apply to the array elements at each position. Lambda function arr1 โ€” The source array of numeric values. Array(T) [arr2, ..., arrN] โ€” Optional. Additional arrays of the same size, passed as arguments to the lambda function if specified. Array(T) Returned value Returns an array of the partial sums of the elements in the source array, with any negative running sum replaced by zero. The result type matches the input array's numeric type. Array(T) Examples Basic usage sql title=Query SELECT arrayCumSumNonNegative([1, 1, -4, 1]) AS res response title=Response [1, 2, 0, 1] With lambda sql title=Query SELECT arrayCumSumNonNegative(x -> x * 2, [1, -2, 3]) AS res response title=Response [2, 0, 6] arrayDifference {#arrayDifference} Introduced in: v1.1 Calculates an array of differences between adjacent array elements. The first element of the result array will be 0, the second arr[1] - arr[0] , the third arr[2] - arr[1] , etc. The type of elements in the result array are determined by the type inference rules for subtraction (e.g. UInt8 - UInt8 = Int16 ). Syntax sql arrayDifference(arr) Arguments arr โ€” Array for which to calculate differences between adjacent elements. Array(T) Returned value Returns an array of differences between adjacent array elements UInt* Examples Usage example sql title=Query SELECT arrayDifference([1, 2, 3, 4]); response title=Response [0,1,1,1] Example of overflow due to result type Int64 sql title=Query SELECT arrayDifference([0, 10000000000000000000]); response title=Response โ”Œโ”€arrayDifference([0, 10000000000000000000])โ”€โ” โ”‚ [0,-8446744073709551616] โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ arrayDistinct {#arrayDistinct} Introduced in: v1.1 Returns an array containing only the distinct elements of an array. Syntax sql arrayDistinct(arr) Arguments arr โ€” Array for which to extract distinct elements. Array(T) Returned value Returns an array containing the distinct elements Array(T) Examples Usage example sql title=Query SELECT arrayDistinct([1, 2, 2, 3, 1]); response title=Response [1,2,3] arrayDotProduct {#arrayDotProduct} Introduced in: v23.5 Returns the dot product of two arrays. :::note The sizes of the two vectors must be equal. Arrays and Tuples may also contain mixed element types. ::: Syntax sql arrayDotProduct(v1, v2)
{"source_file": "array-functions.md"}
[ -0.02183450758457184, 0.03303409367799759, -0.05890487879514694, 0.008886725641787052, -0.08292661607265472, -0.07363095879554749, 0.10736812651157379, -0.013183344155550003, -0.011536823585629463, -0.02238653041422367, -0.07644522935152054, -0.005548423621803522, 0.052367180585861206, -0....
d09d619c-6ab5-415c-9dda-04de68183466
Returns the dot product of two arrays. :::note The sizes of the two vectors must be equal. Arrays and Tuples may also contain mixed element types. ::: Syntax sql arrayDotProduct(v1, v2) Arguments v1 โ€” First vector. Array((U)Int* | Float* | Decimal) or Tuple((U)Int* | Float* | Decimal) v2 โ€” Second vector. Array((U)Int* | Float* | Decimal) or Tuple((U)Int* | Float* | Decimal) Returned value The dot product of the two vectors. :::note The return type is determined by the type of the arguments. If Arrays or Tuples contain mixed element types then the result type is the supertype. ::: (U)Int* or Float* or Decimal Examples Array example sql title=Query SELECT arrayDotProduct([1, 2, 3], [4, 5, 6]) AS res, toTypeName(res); response title=Response 32 UInt16 Tuple example sql title=Query SELECT dotProduct((1::UInt16, 2::UInt8, 3::Float32),(4::Int16, 5::Float32, 6::UInt8)) AS res, toTypeName(res); response title=Response 32 Float64 arrayElement {#arrayElement} Introduced in: v1.1 Gets the element of the provided array with index n where n can be any integer type. If the index falls outside of the bounds of an array, it returns a default value (0 for numbers, an empty string for strings, etc.), except for arguments of a non-constant array and a constant index 0. In this case there will be an error Array indices are 1-based . :::note Arrays in ClickHouse are one-indexed. ::: Negative indexes are supported. In this case, the corresponding element is selected, numbered from the end. For example, arr[-1] is the last item in the array. Operator [n] provides the same functionality. Syntax sql arrayElement(arr, n) Arguments arr โ€” The array to search. Array(T) . - n โ€” Position of the element to get. (U)Int* . Returned value Returns a single combined array from the provided array arguments Array(T) Examples Usage example sql title=Query SELECT arrayElement(arr, 2) FROM (SELECT [1, 2, 3] AS arr) response title=Response 2 Negative indexing sql title=Query SELECT arrayElement(arr, -1) FROM (SELECT [1, 2, 3] AS arr) response title=Response 3 Using [n] notation sql title=Query SELECT arr[2] FROM (SELECT [1, 2, 3] AS arr) response title=Response 2 Index out of array bounds sql title=Query SELECT arrayElement(arr, 4) FROM (SELECT [1, 2, 3] AS arr) response title=Response 0 arrayElementOrNull {#arrayElementOrNull} Introduced in: v1.1 Gets the element of the provided array with index n where n can be any integer type. If the index falls outside of the bounds of an array, NULL is returned instead of a default value. :::note Arrays in ClickHouse are one-indexed. ::: Negative indexes are supported. In this case, it selects the corresponding element numbered from the end. For example, arr[-1] is the last item in the array. Syntax sql arrayElementOrNull(arrays) Arguments arrays โ€” Arbitrary number of array arguments. Array
{"source_file": "array-functions.md"}
[ -0.006358553189784288, -0.024888861924409866, -0.04968647658824921, 0.005907158367335796, 0.016928842291235924, -0.07030989974737167, 0.10429716855287552, -0.04473786801099777, -0.077817901968956, -0.016997462138533592, -0.07080328464508057, -0.031306192278862, 0.03461720421910286, -0.0256...
417a5da6-c84e-4f28-a21e-32d4be14cc35
Syntax sql arrayElementOrNull(arrays) Arguments arrays โ€” Arbitrary number of array arguments. Array Returned value Returns a single combined array from the provided array arguments. Array(T) Examples Usage example sql title=Query SELECT arrayElementOrNull(arr, 2) FROM (SELECT [1, 2, 3] AS arr) response title=Response 2 Negative indexing sql title=Query SELECT arrayElementOrNull(arr, -1) FROM (SELECT [1, 2, 3] AS arr) response title=Response 3 Index out of array bounds sql title=Query SELECT arrayElementOrNull(arr, 4) FROM (SELECT [1, 2, 3] AS arr) response title=Response NULL arrayEnumerate {#arrayEnumerate} Introduced in: v1.1 Returns the array [1, 2, 3, ..., length (arr)] This function is normally used with the ARRAY JOIN clause. It allows counting something just once for each array after applying ARRAY JOIN . This function can also be used in higher-order functions. For example, you can use it to get array indexes for elements that match a condition. Syntax sql arrayEnumerate(arr) Arguments arr โ€” The array to enumerate. Array Returned value Returns the array [1, 2, 3, ..., length (arr)] . Array(UInt32) Examples Basic example with ARRAY JOIN ``sql title=Query CREATE TABLE test ( id UInt8, tag Array(String), version` Array(String) ) ENGINE = MergeTree ORDER BY id; INSERT INTO test VALUES (1, ['release-stable', 'dev', 'security'], ['2.4.0', '2.6.0-alpha', '2.4.0-sec1']); SELECT id, tag, version, seq FROM test ARRAY JOIN tag, version, arrayEnumerate(tag) AS seq ``` response title=Response โ”Œโ”€idโ”€โ”ฌโ”€tagโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€versionโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€seqโ”€โ” โ”‚ 1 โ”‚ release-stable โ”‚ 2.4.0 โ”‚ 1 โ”‚ โ”‚ 1 โ”‚ dev โ”‚ 2.6.0-alpha โ”‚ 2 โ”‚ โ”‚ 1 โ”‚ security โ”‚ 2.4.0-sec1 โ”‚ 3 โ”‚ โ””โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”˜ arrayEnumerateDense {#arrayEnumerateDense} Introduced in: v18.12 Returns an array of the same size as the source array, indicating where each element first appears in the source array. Syntax sql arrayEnumerateDense(arr) Arguments arr โ€” The array to enumerate. Array(T) Returned value Returns an array of the same size as arr , indicating where each element first appears in the source array Array(T) Examples Usage example sql title=Query SELECT arrayEnumerateDense([10, 20, 10, 30]) response title=Response [1,2,1,3] arrayEnumerateDenseRanked {#arrayEnumerateDenseRanked} Introduced in: v20.1 Returns an array the same size as the source array, indicating where each element first appears in the source array. It allows for enumeration of a multidimensional array with the ability to specify how deep to look inside the array. Syntax sql arrayEnumerateDenseRanked(clear_depth, arr, max_array_depth) Arguments clear_depth โ€” Enumerate elements at the specified level separately. Must be less than or equal to max_arr_depth . UInt* arr โ€” N-dimensional array to enumerate. Array(T)
{"source_file": "array-functions.md"}
[ 0.045295584946870804, 0.00966994185000658, -0.025361984968185425, 0.01986808516085148, -0.09137844294309616, -0.0518316887319088, 0.07998333126306534, -0.028617795556783676, -0.005260311532765627, -0.0517803393304348, -0.05662551149725914, 0.02026923932135105, 0.033208027482032776, -0.0708...
54808be2-078b-4a9a-a09e-e90ded6a9207
Arguments clear_depth โ€” Enumerate elements at the specified level separately. Must be less than or equal to max_arr_depth . UInt* arr โ€” N-dimensional array to enumerate. Array(T) max_array_depth โ€” The maximum effective depth. Must be less than or equal to the depth of arr . UInt* Returned value Returns an array denoting where each element first appears in the source array Array Examples Basic usage ```sql title=Query -- With clear_depth=1 and max_array_depth=1, the result is identical to what arrayEnumerateDense would give. SELECT arrayEnumerateDenseRanked(1,[10, 20, 10, 30],1); ``` response title=Response [1,2,1,3] Usage with a multidimensional array ```sql title=Query -- In this example, arrayEnumerateDenseRanked is used to obtain an array indicating, for each element of the -- multidimensional array, what its position is among elements of the same value. -- For the first row of the passed array, [10, 10, 30, 20], the corresponding first row of the result is [1, 1, 2, 3], -- indicating that 10 is the first number encountered in position 1 and 2, 30 the second number encountered in position 3 -- and 20 is the third number encountered in position 4. -- For the second row, [40, 50, 10, 30], the corresponding second row of the result is [4,5,1,2], indicating that 40 -- and 50 are the fourth and fifth numbers encountered in position 1 and 2 of that row, that another 10 -- (the first encountered number) is in position 3 and 30 (the second number encountered) is in the last position. SELECT arrayEnumerateDenseRanked(1,[[10,10,30,20],[40,50,10,30]],2); ``` response title=Response [[1,1,2,3],[4,5,1,2]] Example with increased clear_depth ```sql title=Query -- Changing clear_depth=2 results in the enumeration occurring separately for each row anew. SELECT arrayEnumerateDenseRanked(2,[[10,10,30,20],[40,50,10,30]],2); ``` response title=Response [[1, 1, 2, 3], [1, 2, 3, 4]] arrayEnumerateUniq {#arrayEnumerateUniq} Introduced in: v1.1 Returns an array the same size as the source array, indicating for each element what its position is among elements with the same value. This function is useful when using ARRAY JOIN and aggregation of array elements. The function can take multiple arrays of the same size as arguments. In this case, uniqueness is considered for tuples of elements in the same positions in all the arrays. Syntax sql arrayEnumerateUniq(arr1[, arr2, ... , arrN]) Arguments arr1 โ€” First array to process. Array(T) arr2, ... โ€” Optional. Additional arrays of the same size for tuple uniqueness. Array(UInt32) Returned value Returns an array where each element is the position among elements with the same value or tuple. Array(T) Examples Basic usage sql title=Query SELECT arrayEnumerateUniq([10, 20, 10, 30]); response title=Response [1, 1, 2, 1] Multiple arrays sql title=Query SELECT arrayEnumerateUniq([1, 1, 1, 2, 2, 2], [1, 1, 2, 1, 1, 2]);
{"source_file": "array-functions.md"}
[ -0.0138826509937644, -0.028623206540942192, -0.07414106279611588, -0.01659955270588398, -0.07793431729078293, -0.05153834447264671, 0.07807732373476028, -0.01473313756287098, -0.007889309898018837, -0.030355064198374748, -0.07376992702484131, 0.012064680457115173, 0.0705108568072319, -0.07...
dfd8365b-96f4-4c65-82d1-18144146a29a
response title=Response [1, 1, 2, 1] Multiple arrays sql title=Query SELECT arrayEnumerateUniq([1, 1, 1, 2, 2, 2], [1, 1, 2, 1, 1, 2]); response title=Response [1,2,1,1,2,1] ARRAY JOIN aggregation ```sql title=Query -- Each goal ID has a calculation of the number of conversions (each element in the Goals nested data structure is a goal that was reached, which we refer to as a conversion) -- and the number of sessions. Without ARRAY JOIN, we would have counted the number of sessions as sum(Sign). But in this particular case, -- the rows were multiplied by the nested Goals structure, so in order to count each session one time after this, we apply a condition to the -- value of the arrayEnumerateUniq(Goals.ID) function. SELECT Goals.ID AS GoalID, sum(Sign) AS Reaches, sumIf(Sign, num = 1) AS Visits FROM test.visits ARRAY JOIN Goals, arrayEnumerateUniq(Goals.ID) AS num WHERE CounterID = 160656 GROUP BY GoalID ORDER BY Reaches DESC LIMIT 10 ``` response title=Response โ”Œโ”€โ”€GoalIDโ”€โ”ฌโ”€Reachesโ”€โ”ฌโ”€Visitsโ”€โ” โ”‚ 53225 โ”‚ 3214 โ”‚ 1097 โ”‚ โ”‚ 2825062 โ”‚ 3188 โ”‚ 1097 โ”‚ โ”‚ 56600 โ”‚ 2803 โ”‚ 488 โ”‚ โ”‚ 1989037 โ”‚ 2401 โ”‚ 365 โ”‚ โ”‚ 2830064 โ”‚ 2396 โ”‚ 910 โ”‚ โ”‚ 1113562 โ”‚ 2372 โ”‚ 373 โ”‚ โ”‚ 3270895 โ”‚ 2262 โ”‚ 812 โ”‚ โ”‚ 1084657 โ”‚ 2262 โ”‚ 345 โ”‚ โ”‚ 56599 โ”‚ 2260 โ”‚ 799 โ”‚ โ”‚ 3271094 โ”‚ 2256 โ”‚ 812 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ arrayEnumerateUniqRanked {#arrayEnumerateUniqRanked} Introduced in: v20.1 Returns an array (or multi-dimensional array) with the same dimensions as the source array, indicating for each element what it's position is among elements with the same value. It allows for enumeration of a multi-dimensional array with the ability to specify how deep to look inside the array. Syntax sql arrayEnumerateUniqRanked(clear_depth, arr, max_array_depth) Arguments clear_depth โ€” Enumerate elements at the specified level separately. Positive integer less than or equal to max_arr_depth . UInt* arr โ€” N-dimensional array to enumerate. Array(T) max_array_depth โ€” The maximum effective depth. Positive integer less than or equal to the depth of arr . UInt* Returned value Returns an N-dimensional array the same size as arr with each element showing the position of that element in relation to other elements of the same value. Array(T) Examples Example 1 ```sql title=Query -- With clear_depth=1 and max_array_depth=1, the result of arrayEnumerateUniqRanked -- is identical to that which arrayEnumerateUniq would give for the same array. SELECT arrayEnumerateUniqRanked(1, [1, 2, 1], 1); ``` response title=Response [1, 1, 2] Example 2 ```sql title=Query -- with clear_depth=1 and max_array_depth=1, the result of arrayEnumerateUniqRanked -- is identical to that which arrayEnumerateUniqwould give for the same array. SELECT arrayEnumerateUniqRanked(1, [[1, 2, 3], [2, 2, 1], [3]], 2);", "[[1, 1, 1], [2, 3, 2], [2]] ``` response title=Response [1, 1, 2] Example 3
{"source_file": "array-functions.md"}
[ 0.06423182040452957, 0.058768291026353836, -0.04909422621130943, 0.06594233959913254, -0.061215344816446304, 0.013699410483241081, 0.07806239277124405, -0.004121319390833378, 0.054259005934000015, -0.012967673130333424, -0.10609189420938492, -0.06335944682359695, 0.0940280631184578, 0.0222...
c1e230d8-744f-4fec-8bde-71878fdba8ac
SELECT arrayEnumerateUniqRanked(1, [[1, 2, 3], [2, 2, 1], [3]], 2);", "[[1, 1, 1], [2, 3, 2], [2]] ``` response title=Response [1, 1, 2] Example 3 ```sql title=Query -- In this example, arrayEnumerateUniqRanked is used to obtain an array indicating, -- for each element of the multidimensional array, what its position is among elements -- of the same value. For the first row of the passed array, [1, 2, 3], the corresponding -- result is [1, 1, 1], indicating that this is the first time 1, 2 and 3 are encountered. -- For the second row of the provided array, [2, 2, 1], the corresponding result is [2, 3, 3], -- indicating that 2 is encountered for a second and third time, and 1 is encountered -- for the second time. Likewise, for the third row of the provided array [3] the -- corresponding result is [2] indicating that 3 is encountered for the second time. SELECT arrayEnumerateUniqRanked(1, [[1, 2, 3], [2, 2, 1], [3]], 2); ``` response title=Response [[1, 1, 1], [2, 3, 2], [2]] Example 4 sql title=Query -- Changing clear_depth=2, results in elements being enumerated separately for each row. SELECT arrayEnumerateUniqRanked(2,[[1, 2, 3],[2, 2, 1],[3]], 2); response title=Response [[1, 1, 1], [1, 2, 1], [1]] arrayExcept {#arrayExcept} Introduced in: v25.9 Returns an array containing elements from source that are not present in except , preserving the original order. This function performs a set difference operation between two arrays. For each element in source , it checks if the element exists in except (using exact comparison). If not, the element is included in the result. The operation maintains these properties: 1. Order of elements from source is preserved 2. Duplicates in source are preserved if they don't exist in except 3. NULL is handled as a separate value Syntax sql arrayExcept(source, except) Arguments source โ€” The source array containing elements to filter. Array(T) except โ€” The array containing elements to exclude from the result. Array(T) Returned value Returns an array of the same type as the input array containing elements from source that weren't found in except . Array(T) Examples basic sql title=Query SELECT arrayExcept([1, 2, 3, 2, 4], [3, 5]) response title=Response [1, 2, 2, 4] with_nulls1 sql title=Query SELECT arrayExcept([1, NULL, 2, NULL], [2]) response title=Response [1, NULL, NULL] with_nulls2 sql title=Query SELECT arrayExcept([1, NULL, 2, NULL], [NULL, 2, NULL]) response title=Response [1] strings sql title=Query SELECT arrayExcept(['apple', 'banana', 'cherry'], ['banana', 'date']) response title=Response ['apple', 'cherry'] arrayExists {#arrayExists} Introduced in: v1.1 Returns 1 if there is at least one element in a source array for which func(x[, y1, y2, ... yN]) returns true. Otherwise, it returns 0 . Syntax sql arrayExists(func(x[, y1, ..., yN]), source_arr[, cond1_arr, ... , condN_arr]) Arguments
{"source_file": "array-functions.md"}
[ 0.00846234243363142, -0.0025183898396790028, -0.06820458173751831, -0.031246069818735123, -0.04570554196834564, -0.01411533448845148, 0.08612161129713058, -0.0734717845916748, 0.03680623322725296, -0.029549142345786095, -0.03415462374687195, 0.026487763971090317, 0.10093536227941513, -0.05...
ef0de5b0-10ce-40c8-8fb4-9d8a66732601
Syntax sql arrayExists(func(x[, y1, ..., yN]), source_arr[, cond1_arr, ... , condN_arr]) Arguments func(x[, y1, ..., yN]) โ€” A lambda function which operates on elements of the source array ( x ) and condition arrays ( y ). Lambda function source_arr โ€” The source array to process. Array(T) [, cond1_arr, ... , condN_arr] โ€” Optional. N condition arrays providing additional arguments to the lambda function. Array(T) Returned value Returns 1 if the lambda function returns true for at least one element, 0 otherwise UInt8 Examples Usage example sql title=Query SELECT arrayExists(x, y -> x=y, [1, 2, 3], [0, 0, 0]) response title=Response 0 arrayFill {#arrayFill} Introduced in: v20.1 The arrayFill function sequentially processes a source array from the first element to the last, evaluating a lambda condition at each position using elements from the source and condition arrays. When the lambda function evaluates to false at position i, the function replaces that element with the element at position i-1 from the current state of the array. The first element is always preserved regardless of any condition. Syntax sql arrayFill(func(x [, y1, ..., yN]), source_arr[, cond1_arr, ... , condN_arr]) Arguments func(x [, y1, ..., yN]) โ€” A lambda function func(x [, y1, y2, ... yN]) โ†’ F(x [, y1, y2, ... yN]) which operates on elements of the source array ( x ) and condition arrays ( y ). Lambda function source_arr โ€” The source array to process. Lambda function [, cond1_arr, ... , condN_arr] โ€” Optional. N condition arrays providing additional arguments to the lambda function. Array(T) Returned value Returns an array Array(T) Examples Example with single array sql title=Query SELECT arrayFill(x -> not isNull(x), [1, null, 2, null]) AS res response title=Response [1, 1, 2, 2] Example with two arrays sql title=Query SELECT arrayFill(x, y, z -> x > y AND x < z, [5, 3, 6, 2], [4, 7, 1, 3], [10, 2, 8, 5]) AS res response title=Response [5, 5, 6, 6] arrayFilter {#arrayFilter} Introduced in: v1.1 Returns an array containing only the elements in the source array for which a lambda function returns true. Syntax sql arrayFilter(func(x[, y1, ..., yN]), source_arr[, cond1_arr, ... , condN_arr])] Arguments func(x[, y1, ..., yN]) โ€” A lambda function which operates on elements of the source array ( x ) and condition arrays ( y ). Lambda function source_arr โ€” The source array to process. Array(T) [, cond1_arr, ... , condN_arr] โ€” Optional. N condition arrays providing additional arguments to the lambda function. Array(T) Returned value Returns a subset of the source array Array(T) Examples Example 1 sql title=Query SELECT arrayFilter(x -> x LIKE '%World%', ['Hello', 'abc World']) AS res response title=Response ['abc World'] Example 2
{"source_file": "array-functions.md"}
[ -0.02977333590388298, -0.04867994040250778, -0.05350736528635025, -0.007078228984028101, -0.0015962522011250257, -0.0930369570851326, 0.1652483195066452, -0.08726724237203598, -0.04882107675075531, -0.03207312151789665, -0.06809195131063461, 0.020371589809656143, -0.003411859506741166, -0....
a40b5057-020a-43fc-acbb-96734a7e0081
Examples Example 1 sql title=Query SELECT arrayFilter(x -> x LIKE '%World%', ['Hello', 'abc World']) AS res response title=Response ['abc World'] Example 2 sql title=Query SELECT arrayFilter( (i, x) -> x LIKE '%World%', arrayEnumerate(arr), ['Hello', 'abc World'] AS arr) AS res response title=Response [2] arrayFirst {#arrayFirst} Introduced in: v1.1 Returns the first element in the source array for which func(x[, y1, y2, ... yN]) returns true, otherwise it returns a default value. Syntax sql arrayFirst(func(x[, y1, ..., yN]), source_arr[, cond1_arr, ... , condN_arr]) Arguments func(x[, y1, ..., yN]) โ€” A lambda function which operates on elements of the source array ( x ) and condition arrays ( y ). Lambda function . - source_arr โ€” The source array to process. Array(T) . - [, cond1_arr, ... , condN_arr] โ€” Optional. N condition arrays providing additional arguments to the lambda function. Array(T) . Returned value Returns the first element of the source array for which ฮป is true, otherwise returns the default value of T . Examples Usage example sql title=Query SELECT arrayFirst(x, y -> x=y, ['a', 'b', 'c'], ['c', 'b', 'a']) response title=Response b No match sql title=Query SELECT arrayFirst(x, y -> x=y, [0, 1, 2], [3, 3, 3]) AS res, toTypeName(res) response title=Response 0 UInt8 arrayFirstIndex {#arrayFirstIndex} Introduced in: v1.1 Returns the index of the first element in the source array for which func(x[, y1, y2, ... yN]) returns true, otherwise it returns '0'. Syntax sql arrayFirstIndex(func(x[, y1, ..., yN]), source_arr[, cond1_arr, ... , condN_arr]) Arguments func(x[, y1, ..., yN]) โ€” A lambda function which operates on elements of the source array ( x ) and condition arrays ( y ). Lambda function . - source_arr โ€” The source array to process. Array(T) . - [, cond1_arr, ... , condN_arr] โ€” Optional. N condition arrays providing additional arguments to the lambda function. Array(T) . Returned value Returns the index of the first element of the source array for which func is true, otherwise returns 0 UInt32 Examples Usage example sql title=Query SELECT arrayFirstIndex(x, y -> x=y, ['a', 'b', 'c'], ['c', 'b', 'a']) response title=Response 2 No match sql title=Query SELECT arrayFirstIndex(x, y -> x=y, ['a', 'b', 'c'], ['d', 'e', 'f']) response title=Response 0 arrayFirstOrNull {#arrayFirstOrNull} Introduced in: v1.1 Returns the first element in the source array for which func(x[, y1, y2, ... yN]) returns true, otherwise it returns NULL . Syntax sql arrayFirstOrNull(func(x[, y1, ..., yN]), source_arr[, cond1_arr, ... , condN_arr]) Arguments func(x[, y1, ..., yN]) โ€” A lambda function which operates on elements of the source array ( x ) and condition arrays ( y ). Lambda function source_arr โ€” The source array to process. Array(T)
{"source_file": "array-functions.md"}
[ 0.013500944711267948, -0.00873139500617981, -0.0048922388814389706, 0.023959621787071228, -0.04698747768998146, -0.05840244144201279, 0.16405659914016724, -0.07279331982135773, -0.09334138035774231, -0.029408499598503113, -0.048873741179704666, -0.02189250849187374, 0.011512239463627338, -...
e96c7cff-2c6f-4f8f-a5c9-caa2f98ed229
func(x[, y1, ..., yN]) โ€” A lambda function which operates on elements of the source array ( x ) and condition arrays ( y ). Lambda function source_arr โ€” The source array to process. Array(T) [, cond1_arr, ... , condN_arr] โ€” Optional. N condition arrays providing additional arguments to the lambda function. Array(T) Returned value Returns the first element of the source array for which func is true, otherwise returns NULL . Examples Usage example sql title=Query SELECT arrayFirstOrNull(x, y -> x=y, ['a', 'b', 'c'], ['c', 'b', 'a']) response title=Response b No match sql title=Query SELECT arrayFirstOrNull(x, y -> x=y, [0, 1, 2], [3, 3, 3]) AS res, toTypeName(res) response title=Response NULL Nullable(UInt8) arrayFlatten {#arrayFlatten} Introduced in: v20.1 Converts an array of arrays to a flat array. Function: Applies to any depth of nested arrays. Does not change arrays that are already flat. The flattened array contains all the elements from all source arrays. Syntax sql arrayFlatten(arr) Aliases : flatten Arguments arr โ€” A multidimensional array. Array(Array(T)) Returned value Returns a flattened array from the multidimensional array Array(T) Examples Usage example sql title=Query SELECT arrayFlatten([[[1]], [[2], [3]]]); response title=Response [1, 2, 3] arrayFold {#arrayFold} Introduced in: v23.10 Applies a lambda function to one or more equally-sized arrays and collects the result in an accumulator. Syntax sql arrayFold(ฮป(acc, x1 [, x2, x3, ... xN]), arr1 [, arr2, arr3, ... arrN], acc) Arguments ฮป(x, x1 [, x2, x3, ... xN]) โ€” A lambda function ฮป(acc, x1 [, x2, x3, ... xN]) โ†’ F(acc, x1 [, x2, x3, ... xN]) where F is an operation applied to acc and array values from x with the result of acc re-used. Lambda function arr1 [, arr2, arr3, ... arrN] โ€” N arrays over which to operate. Array(T) acc โ€” Accumulator value with the same type as the return type of the Lambda function. Returned value Returns the final acc value. Examples Usage example sql title=Query SELECT arrayFold(acc,x -> acc + x*2, [1, 2, 3, 4], 3::Int64) AS res; response title=Response 23 Fibonacci sequence sql title=Query SELECT arrayFold(acc, x -> (acc.2, acc.2 + acc.1),range(number),(1::Int64, 0::Int64)).1 AS fibonacci FROM numbers(1,10); response title=Response โ”Œโ”€fibonacciโ”€โ” โ”‚ 0 โ”‚ โ”‚ 1 โ”‚ โ”‚ 1 โ”‚ โ”‚ 2 โ”‚ โ”‚ 3 โ”‚ โ”‚ 5 โ”‚ โ”‚ 8 โ”‚ โ”‚ 13 โ”‚ โ”‚ 21 โ”‚ โ”‚ 34 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Example using multiple arrays sql title=Query SELECT arrayFold( (acc, x, y) -> acc + (x * y), [1, 2, 3, 4], [10, 20, 30, 40], 0::Int64 ) AS res; response title=Response 300 arrayIntersect {#arrayIntersect} Introduced in: v1.1 Takes multiple arrays and returns an array with elements which are present in all source arrays. The result contains only unique values. Syntax
{"source_file": "array-functions.md"}
[ -0.014458107762038708, -0.016368664801120758, -0.04861658066511154, 0.021429257467389107, -0.04000610113143921, -0.030226077884435654, 0.11836166679859161, -0.09120059013366699, -0.055529315024614334, -0.0011947707971557975, -0.056522294878959656, -0.011295734904706478, -0.021249599754810333...
8034ca04-b145-437b-9049-08b1235c4bad
Introduced in: v1.1 Takes multiple arrays and returns an array with elements which are present in all source arrays. The result contains only unique values. Syntax sql arrayIntersect(arr, arr1, ..., arrN) Arguments arrN โ€” N arrays from which to make the new array. Array(T) . Returned value Returns an array with distinct elements that are present in all N arrays Array(T) Examples Usage example sql title=Query SELECT arrayIntersect([1, 2], [1, 3], [2, 3]) AS empty_intersection, arrayIntersect([1, 2], [1, 3], [1, 4]) AS non_empty_intersection response title=Response โ”Œโ”€non_empty_intersectionโ”€โ”ฌโ”€empty_intersectionโ”€โ” โ”‚ [] โ”‚ [1] โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ arrayJaccardIndex {#arrayJaccardIndex} Introduced in: v23.7 Returns the Jaccard index of two arrays. Syntax sql arrayJaccardIndex(arr_x, arr_y) Arguments arr_x โ€” First array. Array(T) arr_y โ€” Second array. Array(T) Returned value Returns the Jaccard index of arr_x and arr_y Float64 Examples Usage example sql title=Query SELECT arrayJaccardIndex([1, 2], [2, 3]) AS res response title=Response 0.3333333333333333 arrayJoin {#arrayJoin} Introduced in: v1.1 The arrayJoin function takes a row that contains an array and unfolds it, generating multiple rows โ€“ one for each element in the array. This is in contrast to Regular Functions in ClickHouse which map input values to output values within the same row, and Aggregate Functions which take a group of rows and "compress" or "reduce" them into a single summary row (or a single value within a summary row if used with GROUP BY ). All the values in the columns are simply copied, except the values in the column where this function is applied; these are replaced with the corresponding array value. Syntax sql arrayJoin(arr) Arguments arr โ€” An array to unfold. Array(T) Returned value Returns a set of rows unfolded from arr . Examples Basic usage sql title=Query SELECT arrayJoin([1, 2, 3] AS src) AS dst, 'Hello', src response title=Response โ”Œโ”€dstโ”€โ”ฌโ”€\'Hello\'โ”€โ”ฌโ”€srcโ”€โ”€โ”€โ”€โ”€โ” โ”‚ 1 โ”‚ Hello โ”‚ [1,2,3] โ”‚ โ”‚ 2 โ”‚ Hello โ”‚ [1,2,3] โ”‚ โ”‚ 3 โ”‚ Hello โ”‚ [1,2,3] โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ arrayJoin affects all sections of the query ```sql title=Query -- The arrayJoin function affects all sections of the query, including the WHERE section. Notice the result 2, even though the subquery returned 1 row. SELECT sum(1) AS impressions FROM ( SELECT ['Istanbul', 'Berlin', 'Bobruisk'] AS cities ) WHERE arrayJoin(cities) IN ['Istanbul', 'Berlin']; ``` response title=Response โ”Œโ”€impressionsโ”€โ” โ”‚ 2 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Using multiple arrayJoin functions ```sql title=Query - A query can use multiple arrayJoin functions. In this case, the transformation is performed multiple times and the rows are multiplied.
{"source_file": "array-functions.md"}
[ 0.027830760926008224, -0.03730266913771629, -0.06418076157569885, 0.03143071010708809, -0.0017969243926927447, -0.09542739391326904, 0.10600420087575912, -0.0928875133395195, -0.023700950667262077, -0.10661857575178146, -0.06470382958650589, 0.027634717524051666, 0.05105537176132202, -0.04...
92c2a2b9-c415-4dad-afc3-1af263b8184d
Using multiple arrayJoin functions ```sql title=Query - A query can use multiple arrayJoin functions. In this case, the transformation is performed multiple times and the rows are multiplied. SELECT sum(1) AS impressions, arrayJoin(cities) AS city, arrayJoin(browsers) AS browser FROM ( SELECT ['Istanbul', 'Berlin', 'Bobruisk'] AS cities, ['Firefox', 'Chrome', 'Chrome'] AS browsers ) GROUP BY 2, 3 ``` response title=Response โ”Œโ”€impressionsโ”€โ”ฌโ”€cityโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€browserโ”€โ” โ”‚ 2 โ”‚ Istanbul โ”‚ Chrome โ”‚ โ”‚ 1 โ”‚ Istanbul โ”‚ Firefox โ”‚ โ”‚ 2 โ”‚ Berlin โ”‚ Chrome โ”‚ โ”‚ 1 โ”‚ Berlin โ”‚ Firefox โ”‚ โ”‚ 2 โ”‚ Bobruisk โ”‚ Chrome โ”‚ โ”‚ 1 โ”‚ Bobruisk โ”‚ Firefox โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Unexpected results due to optimizations ```sql title=Query -- Using multiple arrayJoin with the same expression may not produce the expected result due to optimizations. -- For these cases, consider modifying the repeated array expression with extra operations that do not affect join result. - e.g. arrayJoin(arraySort(arr)), arrayJoin(arrayConcat(arr, [])) SELECT arrayJoin(dice) as first_throw, / arrayJoin(dice) as second_throw / -- is technically correct, but will annihilate result set arrayJoin(arrayConcat(dice, [])) as second_throw -- intentionally changed expression to force re-evaluation FROM ( SELECT [1, 2, 3, 4, 5, 6] as dice ); ``` response title=Response โ”Œโ”€first_throwโ”€โ”ฌโ”€second_throwโ”€โ” โ”‚ 1 โ”‚ 1 โ”‚ โ”‚ 1 โ”‚ 2 โ”‚ โ”‚ 1 โ”‚ 3 โ”‚ โ”‚ 1 โ”‚ 4 โ”‚ โ”‚ 1 โ”‚ 5 โ”‚ โ”‚ 1 โ”‚ 6 โ”‚ โ”‚ 2 โ”‚ 1 โ”‚ โ”‚ 2 โ”‚ 2 โ”‚ โ”‚ 2 โ”‚ 3 โ”‚ โ”‚ 2 โ”‚ 4 โ”‚ โ”‚ 2 โ”‚ 5 โ”‚ โ”‚ 2 โ”‚ 6 โ”‚ โ”‚ 3 โ”‚ 1 โ”‚ โ”‚ 3 โ”‚ 2 โ”‚ โ”‚ 3 โ”‚ 3 โ”‚ โ”‚ 3 โ”‚ 4 โ”‚ โ”‚ 3 โ”‚ 5 โ”‚ โ”‚ 3 โ”‚ 6 โ”‚ โ”‚ 4 โ”‚ 1 โ”‚ โ”‚ 4 โ”‚ 2 โ”‚ โ”‚ 4 โ”‚ 3 โ”‚ โ”‚ 4 โ”‚ 4 โ”‚ โ”‚ 4 โ”‚ 5 โ”‚ โ”‚ 4 โ”‚ 6 โ”‚ โ”‚ 5 โ”‚ 1 โ”‚ โ”‚ 5 โ”‚ 2 โ”‚ โ”‚ 5 โ”‚ 3 โ”‚ โ”‚ 5 โ”‚ 4 โ”‚ โ”‚ 5 โ”‚ 5 โ”‚ โ”‚ 5 โ”‚ 6 โ”‚ โ”‚ 6 โ”‚ 1 โ”‚ โ”‚ 6 โ”‚ 2 โ”‚ โ”‚ 6 โ”‚ 3 โ”‚ โ”‚ 6 โ”‚ 4 โ”‚ โ”‚ 6 โ”‚ 5 โ”‚ โ”‚ 6 โ”‚ 6 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Using the ARRAY JOIN syntax ``sql title=Query -- Note the ARRAY JOIN syntax in the SELECT` query below, which provides broader possibilities. -- ARRAY JOIN allows you to convert multiple arrays with the same number of elements at a time.
{"source_file": "array-functions.md"}
[ 0.02011979930102825, -0.02149444818496704, -0.0005740262567996979, 0.060825053602457047, -0.11579850316047668, -0.03598126024007797, 0.0663154125213623, -0.09297945350408554, -0.05070249363780022, -0.06963697075843811, -0.04613984376192093, -0.06192025914788246, 0.03694984316825867, -0.042...
7d5b7032-054a-40be-a2ec-80dd46e68a47
SELECT sum(1) AS impressions, city, browser FROM ( SELECT ['Istanbul', 'Berlin', 'Bobruisk'] AS cities, ['Firefox', 'Chrome', 'Chrome'] AS browsers ) ARRAY JOIN cities AS city, browsers AS browser GROUP BY 2, 3 ``` response title=Response โ”Œโ”€impressionsโ”€โ”ฌโ”€cityโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€browserโ”€โ” โ”‚ 1 โ”‚ Istanbul โ”‚ Firefox โ”‚ โ”‚ 1 โ”‚ Berlin โ”‚ Chrome โ”‚ โ”‚ 1 โ”‚ Bobruisk โ”‚ Chrome โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Using Tuple ```sql title=Query -- You can also use Tuple SELECT sum(1) AS impressions, (arrayJoin(arrayZip(cities, browsers)) AS t).1 AS city, t.2 AS browser FROM ( SELECT ['Istanbul', 'Berlin', 'Bobruisk'] AS cities, ['Firefox', 'Chrome', 'Chrome'] AS browsers ) GROUP BY 2, 3 ``` response title=Response โ”Œโ”€impressionsโ”€โ”ฌโ”€cityโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€browserโ”€โ” โ”‚ 1 โ”‚ Istanbul โ”‚ Firefox โ”‚ โ”‚ 1 โ”‚ Berlin โ”‚ Chrome โ”‚ โ”‚ 1 โ”‚ Bobruisk โ”‚ Chrome โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ arrayLast {#arrayLast} Introduced in: v1.1 Returns the last element in the source array for which a lambda func(x [, y1, y2, ... yN]) returns true, otherwise it returns a default value. Syntax sql arrayLast(func(x[, y1, ..., yN]), source[, cond1, ... , condN_arr]) Arguments func(x[, y1, ..., yN]) โ€” A lambda function which operates on elements of the source array ( x ) and condition arrays ( y ). Lambda function . - source โ€” The source array to process. Array(T) . - [, cond1, ... , condN] โ€” Optional. N condition arrays providing additional arguments to the lambda function. Array(T) . Returned value Returns the last element of the source array for which func is true, otherwise returns the default value of T . Examples Usage example sql title=Query SELECT arrayLast(x, y -> x=y, ['a', 'b', 'c'], ['a', 'b', 'c']) response title=Response c No match sql title=Query SELECT arrayFirst(x, y -> x=y, [0, 1, 2], [3, 3, 3]) AS res, toTypeName(res) response title=Response 0 UInt8 arrayLastIndex {#arrayLastIndex} Introduced in: v1.1 Returns the index of the last element in the source array for which func(x[, y1, y2, ... yN]) returns true, otherwise it returns '0'. Syntax sql arrayLastIndex(func(x[, y1, ..., yN]), source_arr[, cond1_arr, ... , condN_arr]) Arguments func(x[, y1, ..., yN]) โ€” A lambda function which operates on elements of the source array ( x ) and condition arrays ( y ). Lambda function source_arr โ€” The source array to process. Array(T) [, cond1_arr, ... , condN_arr] โ€” Optional. N condition arrays providing additional arguments to the lambda function. Array(T) Returned value Returns the index of the last element of the source array for which func is true, otherwise returns 0 UInt32 Examples Usage example sql title=Query SELECT arrayLastIndex(x, y -> x=y, ['a', 'b', 'c'], ['a', 'b', 'c']); response title=Response 3 No match
{"source_file": "array-functions.md"}
[ 0.07326813787221909, -0.03785696625709534, -0.0061243143863976, 0.06662455201148987, -0.04704177379608154, -0.003740506013855338, 0.065309077501297, -0.08417575061321259, -0.08074787259101868, -0.041112981736660004, 0.011785470880568027, -0.0638999491930008, 0.01970984786748886, -0.0608716...
bb15cf05-c2c2-4eb6-8502-c20990d13a44
Examples Usage example sql title=Query SELECT arrayLastIndex(x, y -> x=y, ['a', 'b', 'c'], ['a', 'b', 'c']); response title=Response 3 No match sql title=Query SELECT arrayLastIndex(x, y -> x=y, ['a', 'b', 'c'], ['d', 'e', 'f']); response title=Response 0 arrayLastOrNull {#arrayLastOrNull} Introduced in: v1.1 Returns the last element in the source array for which a lambda func(x [, y1, y2, ... yN]) returns true, otherwise it returns NULL . Syntax sql arrayLastOrNull(func(x[, y1, ..., yN]), source_arr[, cond1_arr, ... , condN_arr]) Arguments func(x [, y1, ..., yN]) โ€” A lambda function which operates on elements of the source array ( x ) and condition arrays ( y ). Lambda function . - source_arr โ€” The source array to process. Array(T) . - [, cond1_arr, ... , condN_arr] โ€” Optional. N condition arrays providing additional arguments to the lambda function. Array(T) . Returned value Returns the last element of the source array for which ฮป is not true, otherwise returns NULL . Examples Usage example sql title=Query SELECT arrayLastOrNull(x, y -> x=y, ['a', 'b', 'c'], ['a', 'b', 'c']) response title=Response c No match sql title=Query SELECT arrayLastOrNull(x, y -> x=y, [0, 1, 2], [3, 3, 3]) AS res, toTypeName(res) response title=Response NULL Nullable(UInt8) arrayLevenshteinDistance {#arrayLevenshteinDistance} Introduced in: v25.4 Calculates the Levenshtein distance for two arrays. Syntax sql arrayLevenshteinDistance(from, to) Arguments from โ€” The first array. Array(T) . - to โ€” The second array. Array(T) . Returned value Levenshtein distance between the first and the second arrays. Float64 Examples Usage example sql title=Query SELECT arrayLevenshteinDistance([1, 2, 4], [1, 2, 3]) response title=Response 1 arrayLevenshteinDistanceWeighted {#arrayLevenshteinDistanceWeighted} Introduced in: v25.4 Calculates Levenshtein distance for two arrays with custom weights for each element. The number of elements for the array and its weights should match. Syntax sql arrayLevenshteinDistanceWeighted(from, to, from_weights, to_weights) Arguments from โ€” first array. Array(T) . - to โ€” second array. Array(T) . - from_weights โ€” weights for the first array. Array((U)Int*|Float*) to_weights โ€” weights for the second array. Array((U)Int*|Float*) Returned value Levenshtein distance between the first and the second arrays with custom weights for each element Float64 Examples Usage example sql title=Query SELECT arrayLevenshteinDistanceWeighted(['A', 'B', 'C'], ['A', 'K', 'L'], [1.0, 2, 3], [3.0, 4, 5]) response title=Response 14 arrayMap {#arrayMap} Introduced in: v1.1 Returns an array obtained from the original arrays by applying a lambda function to each element. Syntax sql arrayMap(func, arr) Arguments
{"source_file": "array-functions.md"}
[ -0.004723712336272001, -0.010016611777245998, -0.062204256653785706, 0.022538339719176292, -0.07268825173377991, -0.04820545017719269, 0.11870956420898438, -0.09136810898780823, -0.05947669595479965, -0.01388847827911377, -0.04918208718299866, 0.01578715816140175, -0.014367454685270786, -0...
771ee1cd-b532-4e89-ba23-a5454b36e465
arrayMap {#arrayMap} Introduced in: v1.1 Returns an array obtained from the original arrays by applying a lambda function to each element. Syntax sql arrayMap(func, arr) Arguments func โ€” A lambda function which operates on elements of the source array ( x ) and condition arrays ( y ). Lambda function arr โ€” N arrays to process. Array(T) Returned value Returns an array from the lambda results Array(T) Examples Usage example sql title=Query SELECT arrayMap(x -> (x + 2), [1, 2, 3]) as res; response title=Response [3, 4, 5] Creating a tuple of elements from different arrays sql title=Query SELECT arrayMap((x, y) -> (x, y), [1, 2, 3], [4, 5, 6]) AS res response title=Response [(1, 4),(2, 5),(3, 6)] arrayMax {#arrayMax} Introduced in: v21.1 Returns the maximum element in the source array. If a lambda function func is specified, returns the maximum element of the lambda results. Syntax sql arrayMax([func(x[, y1, ..., yN])], source_arr[, cond1_arr, ... , condN_arr]) Arguments func(x[, y1, ..., yN]) โ€” Optional. A lambda function which operates on elements of the source array ( x ) and condition arrays ( y ). Lambda function source_arr โ€” The source array to process. Array(T) [, cond1_arr, ... , condN_arr] โ€” Optional. N condition arrays providing additional arguments to the lambda function. Array(T) Returned value Returns the maximum element in the source array, or the maximum element of the lambda results if provided. Examples Basic example sql title=Query SELECT arrayMax([5, 3, 2, 7]); response title=Response 7 Usage with lambda function sql title=Query SELECT arrayMax(x, y -> x/y, [4, 8, 12, 16], [1, 2, 1, 2]); response title=Response 12 arrayMin {#arrayMin} Introduced in: v21.1 Returns the minimum element in the source array. If a lambda function func is specified, returns the minimum element of the lambda results. Syntax sql arrayMin([func(x[, y1, ..., yN])], source_arr[, cond1_arr, ... , condN_arr]) Arguments func(x[, y1, ..., yN]) โ€” Optional. A lambda function which operates on elements of the source array ( x ) and condition arrays ( y ). Lambda function source_arr โ€” The source array to process. Array(T) cond1_arr, ... โ€” Optional. N condition arrays providing additional arguments to the lambda function. Array(T) Returned value Returns the minimum element in the source array, or the minimum element of the lambda results if provided. Examples Basic example sql title=Query SELECT arrayMin([5, 3, 2, 7]); response title=Response 2 Usage with lambda function sql title=Query SELECT arrayMin(x, y -> x/y, [4, 8, 12, 16], [1, 2, 1, 2]); response title=Response 4 arrayNormalizedGini {#arrayNormalizedGini} Introduced in: v25.1 Calculates the normalized Gini coefficient. Syntax sql arrayNormalizedGini(predicted, label) Arguments predicted โ€” The predicted value. Array(T)
{"source_file": "array-functions.md"}
[ 0.04797510430216789, -0.018436221405863762, -0.01245829463005066, -0.09356493502855301, -0.029278714209794998, -0.06995467841625214, 0.03343290835618973, -0.047648701816797256, -0.07476449757814407, 0.0027792416512966156, -0.0924469605088234, 0.06416503340005875, 0.006593889556825161, -0.0...
b0be36f5-ce3e-4a6b-9c71-c2e3bbaebc1c
Introduced in: v25.1 Calculates the normalized Gini coefficient. Syntax sql arrayNormalizedGini(predicted, label) Arguments predicted โ€” The predicted value. Array(T) label โ€” The actual value. Array(T) Returned value A tuple containing the Gini coefficients of the predicted values, the Gini coefficient of the normalized values, and the normalized Gini coefficient (= the ratio of the former two Gini coefficients) Tuple(Float64, Float64, Float64) Examples Usage example sql title=Query SELECT arrayNormalizedGini([0.9, 0.3, 0.8, 0.7],[6, 1, 0, 2]); response title=Response (0.18055555555555558, 0.2638888888888889, 0.6842105263157896) arrayPartialReverseSort {#arrayPartialReverseSort} Introduced in: v23.2 This function is the same as arrayReverseSort but with an additional limit argument allowing partial sorting. :::tip To retain only the sorted elements use arrayResize . ::: Syntax sql arrayPartialReverseSort([f,] arr [, arr1, ... ,arrN], limit) Arguments f(arr[, arr1, ... ,arrN]) โ€” The lambda function to apply to elements of array x . Lambda function arr โ€” Array to be sorted. Array(T) arr1, ... ,arrN โ€” N additional arrays, in the case when f accepts multiple arguments. Array(T) limit โ€” Index value up until which sorting will occur. (U)Int* Returned value Returns an array of the same size as the original array where elements in the range [1..limit] are sorted in descending order. The remaining elements (limit..N] are in an unspecified order. Examples simple_int sql title=Query SELECT arrayPartialReverseSort(2, [5, 9, 1, 3]) response title=Response [9, 5, 1, 3] simple_string sql title=Query SELECT arrayPartialReverseSort(2, ['expenses','lasso','embolism','gladly']) response title=Response ['lasso','gladly','expenses','embolism'] retain_sorted sql title=Query SELECT arrayResize(arrayPartialReverseSort(2, [5, 9, 1, 3]), 2) response title=Response [9, 5] lambda_simple sql title=Query SELECT arrayPartialReverseSort((x) -> -x, 2, [5, 9, 1, 3]) response title=Response [1, 3, 5, 9] lambda_complex sql title=Query SELECT arrayPartialReverseSort((x, y) -> -y, 1, [0, 1, 2], [1, 2, 3]) as res response title=Response [0, 1, 2] arrayPartialShuffle {#arrayPartialShuffle} Introduced in: v23.2 Returns an array of the same size as the original array where elements in range [1..limit] are a random subset of the original array. Remaining (limit..n] shall contain the elements not in [1..limit] range in undefined order. Value of limit shall be in range [1..n] . Values outside of that range are equivalent to performing full arrayShuffle : :::note This function will not materialize constants. The value of limit should be in the range [1..N] . Values outside of that range are equivalent to performing full arrayShuffle . ::: Syntax sql arrayPartialShuffle(arr [, limit[, seed]]) Arguments arr โ€” The array to shuffle. Array(T)
{"source_file": "array-functions.md"}
[ -0.0017752338899299502, -0.030550828203558922, -0.049000564962625504, 0.02919943444430828, -0.055127982050180435, -0.030443204566836357, -0.0032880851067602634, 0.001089683035388589, -0.03498496115207672, 0.02451833337545395, -0.06167222186923027, 0.045940808951854706, 0.02408427558839321, ...
1798c75c-d96f-4dbb-bd35-d5c1ca5ea36e
Syntax sql arrayPartialShuffle(arr [, limit[, seed]]) Arguments arr โ€” The array to shuffle. Array(T) seed โ€” Optional. The seed to be used with random number generation. If not provided, a random one is used. (U)Int* limit โ€” Optional. The number to limit element swaps to, in the range [1..N] . (U)Int* Returned value Array with elements partially shuffled. Array(T) Examples no_limit1 sql title=Query SELECT arrayPartialShuffle([1, 2, 3, 4], 0) response title=Response [2, 4, 3, 1] no_limit2 sql title=Query SELECT arrayPartialShuffle([1, 2, 3, 4]) response title=Response [4, 1, 3, 2] random_seed sql title=Query SELECT arrayPartialShuffle([1, 2, 3, 4], 2) response title=Response [3, 4, 1, 2] explicit_seed sql title=Query SELECT arrayPartialShuffle([1, 2, 3, 4], 2, 41) response title=Response [3, 2, 1, 4] materialize sql title=Query SELECT arrayPartialShuffle(materialize([1, 2, 3, 4]), 2, 42), arrayPartialShuffle([1, 2, 3], 2, 42) FROM numbers(10) response title=Response โ”Œโ”€arrayPartialโ‹ฏ4]), 2, 42)โ”€โ”ฌโ”€arrayPartialโ‹ฏ 3], 2, 42)โ”€โ” โ”‚ [3,2,1,4] โ”‚ [3,2,1] โ”‚ โ”‚ [3,2,1,4] โ”‚ [3,2,1] โ”‚ โ”‚ [4,3,2,1] โ”‚ [3,2,1] โ”‚ โ”‚ [1,4,3,2] โ”‚ [3,2,1] โ”‚ โ”‚ [3,4,1,2] โ”‚ [3,2,1] โ”‚ โ”‚ [1,2,3,4] โ”‚ [3,2,1] โ”‚ โ”‚ [1,4,3,2] โ”‚ [3,2,1] โ”‚ โ”‚ [1,4,3,2] โ”‚ [3,2,1] โ”‚ โ”‚ [3,1,2,4] โ”‚ [3,2,1] โ”‚ โ”‚ [1,3,2,4] โ”‚ [3,2,1] โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ arrayPartialSort {#arrayPartialSort} Introduced in: v23.2 This function is the same as arraySort but with an additional limit argument allowing partial sorting. :::tip To retain only the sorted elements use arrayResize . ::: Syntax sql arrayPartialSort([f,] arr [, arr1, ... ,arrN], limit) Arguments f(arr[, arr1, ... ,arrN]) โ€” The lambda function to apply to elements of array x . Lambda function arr โ€” Array to be sorted. Array(T) arr1, ... ,arrN โ€” N additional arrays, in the case when f accepts multiple arguments. Array(T) limit โ€” Index value up until which sorting will occur. (U)Int* Returned value Returns an array of the same size as the original array where elements in the range [1..limit] are sorted in ascending order. The remaining elements (limit..N] are in an unspecified order. Examples simple_int sql title=Query SELECT arrayPartialSort(2, [5, 9, 1, 3]) response title=Response [1, 3, 5, 9] simple_string sql title=Query SELECT arrayPartialSort(2, ['expenses', 'lasso', 'embolism', 'gladly']) response title=Response ['embolism', 'expenses', 'gladly', 'lasso'] retain_sorted sql title=Query SELECT arrayResize(arrayPartialSort(2, [5, 9, 1, 3]), 2) response title=Response [1, 3] lambda_simple
{"source_file": "array-functions.md"}
[ -0.01698898896574974, 0.006241893861442804, 0.008300721645355225, 0.01613171212375164, -0.05224732682108879, -0.07793844491243362, 0.09121973812580109, -0.12851962447166443, -0.01369372196495533, -0.041505102068185806, -0.02702607400715351, 0.0480433888733387, 0.02478375844657421, -0.11940...
4bbe4412-06a0-43f9-ac53-4e82306d29be
retain_sorted sql title=Query SELECT arrayResize(arrayPartialSort(2, [5, 9, 1, 3]), 2) response title=Response [1, 3] lambda_simple sql title=Query SELECT arrayPartialSort((x) -> -x, 2, [5, 9, 1, 3]) response title=Response [9, 5, 1, 3] lambda_complex sql title=Query SELECT arrayPartialSort((x, y) -> -y, 1, [0, 1, 2], [1, 2, 3]) as res response title=Response [2, 1, 0] arrayPopBack {#arrayPopBack} Introduced in: v1.1 Removes the last element from the array. Syntax sql arrayPopBack(arr) Arguments arr โ€” The array for which to remove the last element from. Array(T) Returned value Returns an array identical to arr but without the last element of arr Array(T) Examples Usage example sql title=Query SELECT arrayPopBack([1, 2, 3]) AS res; response title=Response [1, 2] arrayPopFront {#arrayPopFront} Introduced in: v1.1 Removes the first item from the array. Syntax sql arrayPopFront(arr) Arguments arr โ€” The array for which to remove the first element from. Array(T) Returned value Returns an array identical to arr but without the first element of arr Array(T) Examples Usage example sql title=Query SELECT arrayPopFront([1, 2, 3]) AS res; response title=Response [2, 3] arrayProduct {#arrayProduct} Introduced in: v21.1 Returns the product of elements in the source array. If a lambda function func is specified, returns the product of elements of the lambda results. Syntax sql arrayProduct([func(x[, y1, ..., yN])], source_arr[, cond1_arr, ... , condN_arr]) Arguments func(x[, y1, ..., yN]) โ€” Optional. A lambda function which operates on elements of the source array ( x ) and condition arrays ( y ). Lambda function source_arr โ€” The source array to process. Array(T) [, cond1_arr, ... , condN_arr] โ€” Optional. N condition arrays providing additional arguments to the lambda function. Array(T) Returned value Returns the product of elements in the source array, or the product of elements of the lambda results if provided. Float64 Examples Basic example sql title=Query SELECT arrayProduct([1, 2, 3, 4]); response title=Response 24 Usage with lambda function sql title=Query SELECT arrayProduct(x, y -> x+y, [2, 2], [2, 2]) AS res; response title=Response 16 arrayPushBack {#arrayPushBack} Introduced in: v1.1 Adds one item to the end of the array. Syntax sql arrayPushBack(arr, x) Arguments arr โ€” The array for which to add value x to the end of. Array(T) x โ€” Single value to add to the end of the array. Array(T) . :::note - Only numbers can be added to an array with numbers, and only strings can be added to an array of strings. - When adding numbers, ClickHouse automatically sets the type of x for the data type of the array. - Can be NULL . The function adds a NULL element to an array, and the type of array elements converts to Nullable .
{"source_file": "array-functions.md"}
[ 0.011703620664775372, 0.0197690911591053, 0.020430857315659523, 0.0286418404430151, -0.05330495908856392, -0.05977161228656769, 0.10719103366136551, -0.07200310379266739, 0.016896061599254608, -0.023118026554584503, -0.010752878151834011, 0.10789141803979874, -0.010032441467046738, -0.0518...
3d6fec48-8a06-4dde-b7d6-f42a211c6db0
For more information about the types of data in ClickHouse, see Data types . ::: Returned value Returns an array identical to arr but with an additional value x at the end of the array Array(T) Examples Usage example sql title=Query SELECT arrayPushBack(['a'], 'b') AS res; response title=Response ['a','b'] arrayPushFront {#arrayPushFront} Introduced in: v1.1 Adds one element to the beginning of the array. Syntax sql arrayPushFront(arr, x) Arguments arr โ€” The array for which to add value x to the end of. Array(T) . - x โ€” Single value to add to the start of the array. Array(T) . :::note - Only numbers can be added to an array with numbers, and only strings can be added to an array of strings. - When adding numbers, ClickHouse automatically sets the type of x for the data type of the array. - Can be NULL . The function adds a NULL element to an array, and the type of array elements converts to Nullable . For more information about the types of data in ClickHouse, see Data types . ::: Returned value Returns an array identical to arr but with an additional value x at the beginning of the array Array(T) Examples Usage example sql title=Query SELECT arrayPushFront(['b'], 'a') AS res; response title=Response ['a','b'] arrayROCAUC {#arrayROCAUC} Introduced in: v20.4 Calculates the area under the receiver operating characteristic (ROC) curve. A ROC curve is created by plotting True Positive Rate (TPR) on the y-axis and False Positive Rate (FPR) on the x-axis across all thresholds. The resulting value ranges from zero to one, with a higher value indicating better model performance. The ROC AUC (also known as simply AUC) is a concept in machine learning. For more details, please see here , here and here . Syntax sql arrayROCAUC(scores, labels[, scale[, partial_offsets]]) Aliases : arrayAUC Arguments scores โ€” Scores prediction model gives. Array((U)Int*) or Array(Float*) labels โ€” Labels of samples, usually 1 for positive sample and 0 for negative sample. Array((U)Int*) or Enum scale โ€” Optional. Decides whether to return the normalized area. If false, returns the area under the TP (true positives) x FP (false positives) curve instead. Default value: true. Bool partial_offsets โ€” An array of four non-negative integers for calculating a partial area under the ROC curve (equivalent to a vertical band of the ROC space) instead of the whole AUC. This option is useful for distributed computation of the ROC AUC. The array must contain the following elements [ higher_partitions_tp , higher_partitions_fp , total_positives , total_negatives ]. Array of non-negative Integers . Optional. higher_partitions_tp : The number of positive labels in the higher-scored partitions. higher_partitions_fp : The number of negative labels in the higher-scored partitions. total_positives : The total number of positive samples in the entire dataset.
{"source_file": "array-functions.md"}
[ 0.001954379491508007, -0.01535799354314804, -0.0931052714586258, 0.040506985038518906, -0.12030231952667236, -0.04927956685423851, 0.08387189358472824, -0.04654747620224953, 0.002295848447829485, -0.02950211986899376, 0.005595416761934757, 0.04707050323486328, 0.020856395363807678, -0.0796...
56da1bc3-8a79-4498-9e97-244c0d5d34e2
higher_partitions_fp : The number of negative labels in the higher-scored partitions. total_positives : The total number of positive samples in the entire dataset. total_negatives : The total number of negative samples in the entire dataset. ::::note When arr_partial_offsets is used, the arr_scores and arr_labels should be only a partition of the entire dataset, containing an interval of scores. The dataset should be divided into contiguous partitions, where each partition contains the subset of the data whose scores fall within a specific range. For example: - One partition could contain all scores in the range [0, 0.5). - Another partition could contain scores in the range [0.5, 1.0]. :::: Returned value Returns area under the receiver operating characteristic (ROC) curve. Float64 Examples Usage example sql title=Query SELECT arrayROCAUC([0.1, 0.4, 0.35, 0.8], [0, 0, 1, 1]); response title=Response 0.75 arrayRandomSample {#arrayRandomSample} Introduced in: v23.10 Returns a subset with samples -many random elements of an input array. If samples exceeds the size of the input array, the sample size is limited to the size of the array, i.e. all array elements are returned but their order is not guaranteed. The function can handle both flat arrays and nested arrays. Syntax sql arrayRandomSample(arr, samples) Arguments arr โ€” The input array or multidimensional array from which to sample elements. Array(T) samples โ€” The number of elements to include in the random sample. (U)Int* Returned value An array containing a random sample of elements from the input array Array(T) Examples Usage example sql title=Query SELECT arrayRandomSample(['apple', 'banana', 'cherry', 'date'], 2) as res; response title=Response ['cherry','apple'] Using a multidimensional array sql title=Query SELECT arrayRandomSample([[1, 2], [3, 4], [5, 6]], 2) as res; response title=Response [[3,4],[5,6]] arrayReduce {#arrayReduce} Introduced in: v1.1 Applies an aggregate function to array elements and returns its result. The name of the aggregation function is passed as a string in single quotes 'max' , 'sum' . When using parametric aggregate functions, the parameter is indicated after the function name in parentheses 'uniqUpTo(6)' . Syntax sql arrayReduce(agg_f, arr1 [, arr2, ... , arrN)]) Arguments agg_f โ€” The name of an aggregate function which should be a constant. String arr1 [, arr2, ... , arrN)] โ€” N arrays corresponding to the arguments of agg_f . Array(T) Returned value Returns the result of the aggregate function Examples Usage example sql title=Query SELECT arrayReduce('max', [1, 2, 3]); response title=Response โ”Œโ”€arrayReduce('max', [1, 2, 3])โ”€โ” โ”‚ 3 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Example with aggregate function using multiple arguments
{"source_file": "array-functions.md"}
[ 0.03137953206896782, -0.035551514476537704, -0.07307747006416321, -0.021355770528316498, 0.051721733063459396, -0.03076021932065487, 0.050455302000045776, 0.08822459727525711, -0.003472586628049612, -0.06532800942659378, -0.02938273176550865, -0.0565326027572155, -0.01198720745742321, 0.04...
4bc6b9d4-c717-4ab8-8471-abfa9ef60173
response title=Response โ”Œโ”€arrayReduce('max', [1, 2, 3])โ”€โ” โ”‚ 3 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Example with aggregate function using multiple arguments ```sql title=Query --If an aggregate function takes multiple arguments, then this function must be applied to multiple arrays of the same size. SELECT arrayReduce('maxIf', [3, 5], [1, 0]); ``` response title=Response โ”Œโ”€arrayReduce('maxIf', [3, 5], [1, 0])โ”€โ” โ”‚ 3 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Example with a parametric aggregate function sql title=Query SELECT arrayReduce('uniqUpTo(3)', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); response title=Response โ”Œโ”€arrayReduce('uniqUpTo(3)', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])โ”€โ” โ”‚ 4 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ arrayReduceInRanges {#arrayReduceInRanges} Introduced in: v20.4 Applies an aggregate function to array elements in the given ranges and returns an array containing the result corresponding to each range. The function will return the same result as multiple arrayReduce(agg_func, arraySlice(arr1, index, length), ...) . Syntax sql arrayReduceInRanges(agg_f, ranges, arr1 [, arr2, ... ,arrN)]) Arguments agg_f โ€” The name of the aggregate function to use. String ranges โ€” The range over which to aggregate. An array of tuples, (i, r) containing the index i from which to begin from and the range r over which to aggregate. Array(T) or Tuple(T) arr1 [, arr2, ... ,arrN)] โ€” N arrays as arguments to the aggregate function. Array(T) Returned value Returns an array containing results of the aggregate function over the specified ranges Array(T) Examples Usage example sql title=Query SELECT arrayReduceInRanges( 'sum', [(1, 5), (2, 3), (3, 4), (4, 4)], [1000000, 200000, 30000, 4000, 500, 60, 7] ) AS res response title=Response โ”Œโ”€resโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ [1234500,234000,34560,4567] โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ arrayResize {#arrayResize} Introduced in: v1.1 Changes the length of the array. Syntax sql arrayResize(arr, size[, extender]) Arguments arr โ€” Array to resize. Array(T) size โ€” -The new length of the array. If size is less than the original size of the array, the array is truncated from the right. If size is larger than the initial size of the array, the array is extended to the right with extender values or default values for the data type of the array items. extender โ€” Value to use for extending the array. Can be NULL . Returned value An array of length size . Array(T) Examples Example 1 sql title=Query SELECT arrayResize([1], 3); response title=Response [1,0,0] Example 2 sql title=Query SELECT arrayResize([1], 3, NULL); response title=Response [1,NULL,NULL] arrayReverse {#arrayReverse} Introduced in: v1.1 Reverses the order of elements of a given array.
{"source_file": "array-functions.md"}
[ 0.003100433386862278, -0.01400063931941986, 0.008773463778197765, -0.043090883642435074, -0.0375913605093956, -0.00973666924983263, 0.022984646260738373, -0.01796618290245533, -0.026987917721271515, -0.04506026580929756, -0.06686735898256302, 0.029485812410712242, 0.030944842845201492, -0....
e6bc8f7f-6b37-4470-9ad9-9bcc3c91dfba
sql title=Query SELECT arrayResize([1], 3, NULL); response title=Response [1,NULL,NULL] arrayReverse {#arrayReverse} Introduced in: v1.1 Reverses the order of elements of a given array. :::note Function reverse(arr) performs the same functionality but works on other data-types in addition to Arrays. ::: Syntax sql arrayReverse(arr) Arguments arr โ€” The array to reverse. Array(T) Returned value Returns an array of the same size as the original array containing the elements in reverse order Array(T) Examples Usage example sql title=Query SELECT arrayReverse([1, 2, 3]) response title=Response [3,2,1] arrayReverseFill {#arrayReverseFill} Introduced in: v20.1 The arrayReverseFill function sequentially processes a source array from the last element to the first, evaluating a lambda condition at each position using elements from the source and condition arrays. When the condition evaluates to false at position i, the function replaces that element with the element at position i+1 from the current state of the array. The last element is always preserved regardless of any condition. Syntax sql arrayReverseFill(func(x[, y1, ..., yN]), source_arr[, cond1_arr, ... , condN_arr]) Arguments func(x[, y1, ..., yN]) โ€” A lambda function which operates on elements of the source array ( x ) and condition arrays ( y ). Lambda function source_arr โ€” The source array to process. Array(T) [, cond1_arr, ... , condN_arr] โ€” Optional. N condition arrays providing additional arguments to the lambda function. Array(T) Returned value Returns an array with elements of the source array replaced by the results of the lambda. Array(T) Examples Example with a single array sql title=Query SELECT arrayReverseFill(x -> not isNull(x), [1, null, 2, null]) AS res response title=Response [1, 2, 2, NULL] Example with two arrays sql title=Query SELECT arrayReverseFill(x, y, z -> x > y AND x < z, [5, 3, 6, 2], [4, 7, 1, 3], [10, 2, 8, 5]) AS res; response title=Response [5, 6, 6, 2] arrayReverseSort {#arrayReverseSort} Introduced in: v1.1 Sorts the elements of an array in descending order. If a function f is specified, the provided array is sorted according to the result of the function applied to the elements of the array, and then the sorted array is reversed. If f accepts multiple arguments, the arrayReverseSort function is passed several arrays that the arguments of func will correspond to. If the array to sort contains -Inf , NULL , NaN , or Inf they will be sorted in the following order: -Inf Inf NaN NULL arrayReverseSort is a higher-order function . Syntax sql arrayReverseSort([f,] arr [, arr1, ... ,arrN) Arguments f(y1[, y2 ... yN]) โ€” The lambda function to apply to elements of array x . - arr โ€” An array to be sorted. Array(T) - arr1, ..., yN โ€” Optional. N additional arrays, in the case when f accepts multiple arguments. Returned value
{"source_file": "array-functions.md"}
[ -0.020979037508368492, 0.007516556419432163, 0.04243282228708267, 0.006765032187104225, -0.10573931783437729, -0.08323787897825241, 0.008171281777322292, -0.07575346529483795, 0.010955924168229103, 0.02608485333621502, -0.04550936073064804, 0.08062991499900818, -0.01726934127509594, -0.067...
c15cfcc3-bab1-43a7-8215-c175e42ccdc6
Returned value Returns the array x sorted in descending order if no lambda function is provided, otherwise it returns an array sorted according to the logic of the provided lambda function, and then reversed. Array(T) . Examples Example 1 sql title=Query SELECT arrayReverseSort((x, y) -> y, [4, 3, 5], ['a', 'b', 'c']) AS res; response title=Response [5,3,4] Example 2 sql title=Query SELECT arrayReverseSort((x, y) -> -y, [4, 3, 5], [1, 2, 3]) AS res; response title=Response [4,3,5] arrayReverseSplit {#arrayReverseSplit} Introduced in: v20.1 Split a source array into multiple arrays. When func(x[, y1, ..., yN]) returns something other than zero, the array will be split to the right of the element. The array will not be split after the last element. Syntax sql arrayReverseSplit(func(x[, y1, ..., yN]), source_arr[, cond1_arr, ... , condN_arr]) Arguments func(x[, y1, ..., yN]) โ€” A lambda function which operates on elements of the source array ( x ) and condition arrays ( y ). Lambda function source_arr โ€” The source array to process. Lambda function [, cond1_arr, ... , condN_arr] โ€” Optional. N condition arrays providing additional arguments to the lambda function. Array(T) Returned value Returns an array of arrays. Array(Array(T)) Examples Usage example sql title=Query SELECT arrayReverseSplit((x, y) -> y, [1, 2, 3, 4, 5], [1, 0, 0, 1, 0]) AS res response title=Response [[1], [2, 3, 4], [5]] arrayRotateLeft {#arrayRotateLeft} Introduced in: v23.8 Rotates an array to the left by the specified number of elements. Negative values of n are treated as rotating to the right by the absolute value of the rotation. Syntax sql arrayRotateLeft(arr, n) Arguments arr โ€” The array for which to rotate the elements. Array(T) . - n โ€” Number of elements to rotate. (U)Int8/16/32/64 . Returned value An array rotated to the left by the specified number of elements Array(T) Examples Usage example sql title=Query SELECT arrayRotateLeft([1,2,3,4,5,6], 2) as res; response title=Response [3,4,5,6,1,2] Negative value of n sql title=Query SELECT arrayRotateLeft([1,2,3,4,5,6], -2) as res; response title=Response [5,6,1,2,3,4] arrayRotateRight {#arrayRotateRight} Introduced in: v23.8 Rotates an array to the right by the specified number of elements. Negative values of n are treated as rotating to the left by the absolute value of the rotation. Syntax sql arrayRotateRight(arr, n) Arguments arr โ€” The array for which to rotate the elements. Array(T) . - n โ€” Number of elements to rotate. (U)Int8/16/32/64 . Returned value An array rotated to the right by the specified number of elements Array(T) Examples Usage example sql title=Query SELECT arrayRotateRight([1,2,3,4,5,6], 2) as res; response title=Response [5,6,1,2,3,4] Negative value of n sql title=Query SELECT arrayRotateRight([1,2,3,4,5,6], -2) as res;
{"source_file": "array-functions.md"}
[ 0.0038826395757496357, -0.04769419506192207, 0.029501518234610558, -0.024201836436986923, -0.07324354350566864, -0.04953001067042351, 0.06373927742242813, -0.03162720054388046, -0.02686876244843006, 0.024370204657316208, -0.022859036922454834, 0.09016746282577515, -0.020443834364414215, 0....
e884ebc2-f973-402e-b897-2fab0b0f28dd
sql title=Query SELECT arrayRotateRight([1,2,3,4,5,6], 2) as res; response title=Response [5,6,1,2,3,4] Negative value of n sql title=Query SELECT arrayRotateRight([1,2,3,4,5,6], -2) as res; response title=Response [3,4,5,6,1,2] arrayShiftLeft {#arrayShiftLeft} Introduced in: v23.8 Shifts an array to the left by the specified number of elements. New elements are filled with the provided argument or the default value of the array element type. If the number of elements is negative, the array is shifted to the right. Syntax sql arrayShiftLeft(arr, n[, default]) Arguments arr โ€” The array for which to shift the elements. Array(T) . - n โ€” Number of elements to shift. (U)Int8/16/32/64 . - default โ€” Optional. Default value for new elements. Returned value An array shifted to the left by the specified number of elements Array(T) Examples Usage example sql title=Query SELECT arrayShiftLeft([1,2,3,4,5,6], 2) as res; response title=Response [3,4,5,6,0,0] Negative value of n sql title=Query SELECT arrayShiftLeft([1,2,3,4,5,6], -2) as res; response title=Response [0,0,1,2,3,4] Using a default value sql title=Query SELECT arrayShiftLeft([1,2,3,4,5,6], 2, 42) as res; response title=Response [3,4,5,6,42,42] arrayShiftRight {#arrayShiftRight} Introduced in: v23.8 Shifts an array to the right by the specified number of elements. New elements are filled with the provided argument or the default value of the array element type. If the number of elements is negative, the array is shifted to the left. Syntax sql arrayShiftRight(arr, n[, default]) Arguments arr โ€” The array for which to shift the elements. Array(T) n โ€” Number of elements to shift. (U)Int8/16/32/64 default โ€” Optional. Default value for new elements. Returned value An array shifted to the right by the specified number of elements Array(T) Examples Usage example sql title=Query SELECT arrayShiftRight([1, 2, 3, 4, 5, 6], 2) as res; response title=Response [0, 0, 1, 2, 3, 4] Negative value of n sql title=Query SELECT arrayShiftRight([1, 2, 3, 4, 5, 6], -2) as res; response title=Response [3, 4, 5, 6, 0, 0] Using a default value sql title=Query SELECT arrayShiftRight([1, 2, 3, 4, 5, 6], 2, 42) as res; response title=Response [42, 42, 1, 2, 3, 4] arrayShingles {#arrayShingles} Introduced in: v24.1 Generates an array of shingles (similar to ngrams for strings), i.e. consecutive sub-arrays with a specified length of the input array. Syntax sql arrayShingles(arr, l) Arguments arr โ€” Array for which to generate an array of shingles. Array(T) l โ€” The length of each shingle. (U)Int* Returned value An array of generated shingles Array(T) Examples Usage example sql title=Query SELECT arrayShingles([1, 2, 3, 4], 3) as res; response title=Response [[1, 2, 3], [2, 3, 4]] arrayShuffle {#arrayShuffle} Introduced in: v23.2
{"source_file": "array-functions.md"}
[ 0.04735978692770004, 0.021795129403471947, -0.02721375599503517, -0.005374323111027479, -0.1281936913728714, -0.059368155896663666, 0.08237003535032272, -0.023480936884880066, -0.01524724718183279, -0.032365478575229645, -0.03944902867078781, 0.04115133360028267, 0.032066710293293, -0.0547...
f10ceb60-d115-4ede-a193-b2c0988736cc
Examples Usage example sql title=Query SELECT arrayShingles([1, 2, 3, 4], 3) as res; response title=Response [[1, 2, 3], [2, 3, 4]] arrayShuffle {#arrayShuffle} Introduced in: v23.2 Returns an array of the same size as the original array containing the elements in shuffled order. Elements are reordered in such a way that each possible permutation of those elements has equal probability of appearance. :::note This function will not materialize constants. ::: Syntax sql arrayShuffle(arr [, seed]) Arguments arr โ€” The array to shuffle. Array(T) seed (optional) โ€” Optional. The seed to be used with random number generation. If not provided a random one is used. (U)Int* Returned value Array with elements shuffled Array(T) Examples Example without seed (unstable results) sql title=Query SELECT arrayShuffle([1, 2, 3, 4]); response title=Response [1,4,2,3] Example without seed (stable results) sql title=Query SELECT arrayShuffle([1, 2, 3, 4], 41); response title=Response [3,2,1,4] arraySimilarity {#arraySimilarity} Introduced in: v25.4 Calculates the similarity of two arrays from 0 to 1 based on weighted Levenshtein distance. Syntax sql arraySimilarity(from, to, from_weights, to_weights) Arguments from โ€” first array Array(T) to โ€” second array Array(T) from_weights โ€” weights for the first array. Array((U)Int*|Float*) to_weights โ€” weights for the second array. Array((U)Int*|Float*) Returned value Returns the similarity between 0 and 1 of the two arrays based on the weighted Levenshtein distance Float64 Examples Usage example sql title=Query SELECT arraySimilarity(['A', 'B', 'C'], ['A', 'K', 'L'], [1.0, 2, 3], [3.0, 4, 5]); response title=Response 0.2222222222222222 arraySlice {#arraySlice} Introduced in: v1.1 Returns a slice of the array, with NULL elements included. Syntax sql arraySlice(arr, offset [, length]) Arguments arr โ€” Array to slice. Array(T) offset โ€” Indent from the edge of the array. A positive value indicates an offset on the left, and a negative value is an indent on the right. Numbering of the array items begins with 1 . (U)Int* length โ€” The length of the required slice. If you specify a negative value, the function returns an open slice [offset, array_length - length] . If you omit the value, the function returns the slice [offset, the_end_of_array] . (U)Int* Returned value Returns a slice of the array with length elements from the specified offset Array(T) Examples Usage example sql title=Query SELECT arraySlice([1, 2, NULL, 4, 5], 2, 3) AS res; response title=Response [2, NULL, 4] arraySort {#arraySort} Introduced in: v1.1
{"source_file": "array-functions.md"}
[ -0.012000086717307568, 0.03700912371277809, -0.018214764073491096, -0.011603527702391148, -0.06013673171401024, -0.06977149844169617, 0.08678276836872101, -0.13974741101264954, 0.007582506164908409, -0.021884463727474213, -0.05197214335203171, 0.0766308382153511, 0.06925535202026367, -0.12...
7551321b-2f0c-4c3e-86cb-d7a38682ea8c
Examples Usage example sql title=Query SELECT arraySlice([1, 2, NULL, 4, 5], 2, 3) AS res; response title=Response [2, NULL, 4] arraySort {#arraySort} Introduced in: v1.1 Sorts the elements of the provided array in ascending order. If a lambda function f is specified, sorting order is determined by the result of the lambda applied to each element of the array. If the lambda accepts multiple arguments, the arraySort function is passed several arrays that the arguments of f will correspond to. If the array to sort contains -Inf , NULL , NaN , or Inf they will be sorted in the following order: -Inf Inf NaN NULL arraySort is a higher-order function . Syntax sql arraySort([f,] arr [, arr1, ... ,arrN]) Arguments f(y1[, y2 ... yN]) โ€” The lambda function to apply to elements of array x . - arr โ€” An array to be sorted. Array(T) - arr1, ..., yN โ€” Optional. N additional arrays, in the case when f accepts multiple arguments. Returned value Returns the array arr sorted in ascending order if no lambda function is provided, otherwise it returns an array sorted according to the logic of the provided lambda function. Array(T) . Examples Example 1 sql title=Query SELECT arraySort([1, 3, 3, 0]); response title=Response [0,1,3,3] Example 2 sql title=Query SELECT arraySort(['hello', 'world', '!']); response title=Response ['!','hello','world'] Example 3 sql title=Query SELECT arraySort([1, nan, 2, NULL, 3, nan, -4, NULL, inf, -inf]); response title=Response [-inf,-4,1,2,3,inf,nan,nan,NULL,NULL] arraySplit {#arraySplit} Introduced in: v20.1 Split a source array into multiple arrays. When func(x [, y1, ..., yN]) returns something other than zero, the array will be split to the left of the element. The array will not be split before the first element. Syntax sql arraySplit(func(x[, y1, ..., yN]), source_arr[, cond1_arr, ... , condN_arr]) Arguments func(x[, y1, ..., yN]) โ€” A lambda function which operates on elements of the source array ( x ) and condition arrays ( y ). Lambda function . - source_arr โ€” The source array to split Array(T) . - [, cond1_arr, ... , condN_arr] โ€” Optional. N condition arrays providing additional arguments to the lambda function. Array(T) . Returned value Returns an array of arrays Array(Array(T)) Examples Usage example sql title=Query SELECT arraySplit((x, y) -> y, [1, 2, 3, 4, 5], [1, 0, 0, 1, 0]) AS res response title=Response [[1, 2, 3], [4, 5]] arraySum {#arraySum} Introduced in: v21.1 Returns the sum of elements in the source array. If a lambda function func is specified, returns the sum of elements of the lambda results. Syntax sql arrayMax([func(x[, y1, ..., yN])], source_arr[, cond1_arr, ... , condN_arr]) Arguments func(x[, y1, ..., yN]) โ€” Optional. A lambda function which operates on elements of the source array ( x ) and condition arrays ( y ). Lambda function
{"source_file": "array-functions.md"}
[ 0.006020182278007269, -0.04754437133669853, -0.0164162740111351, -0.026995625346899033, -0.028057221323251724, -0.08323659002780914, 0.06376361846923828, 0.008016555570065975, -0.016670551151037216, 0.044774968177080154, -0.005541249644011259, 0.12173398584127426, 0.001296377507969737, 0.0...
059548a3-e6be-4e7c-9161-3ca71a268ce2
Arguments func(x[, y1, ..., yN]) โ€” Optional. A lambda function which operates on elements of the source array ( x ) and condition arrays ( y ). Lambda function source_arr โ€” The source array to process. Array(T) , cond1_arr, ... , condN_arr] โ€” Optional. N condition arrays providing additional arguments to the lambda function. Array(T) Returned value Returns the sum of elements in the source array, or the sum of elements of the lambda results if provided. Examples Basic example sql title=Query SELECT arraySum([1, 2, 3, 4]); response title=Response 10 Usage with lambda function sql title=Query SELECT arraySum(x, y -> x+y, [1, 1, 1, 1], [1, 1, 1, 1]); response title=Response 8 arraySymmetricDifference {#arraySymmetricDifference} Introduced in: v25.4 Takes multiple arrays and returns an array with elements that are not present in all source arrays. The result contains only unique values. :::note The symmetric difference of more than two sets is mathematically defined as the set of all input elements which occur in an odd number of input sets. In contrast, function arraySymmetricDifference simply returns the set of input elements which do not occur in all input sets. ::: Syntax sql arraySymmetricDifference(arr1, arr2, ... , arrN) Arguments arrN โ€” N arrays from which to make the new array. Array(T) . Returned value Returns an array of distinct elements not present in all source arrays Array(T) Examples Usage example sql title=Query SELECT arraySymmetricDifference([1, 2], [1, 2], [1, 2]) AS empty_symmetric_difference, arraySymmetricDifference([1, 2], [1, 2], [1, 3]) AS non_empty_symmetric_difference; response title=Response โ”Œโ”€empty_symmetric_differenceโ”€โ”ฌโ”€non_empty_symmetric_differenceโ”€โ” โ”‚ [] โ”‚ [3] โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ arrayUnion {#arrayUnion} Introduced in: v24.10 Takes multiple arrays and returns an array which contains all elements that are present in one of the source arrays.The result contains only unique values. Syntax sql arrayUnion(arr1, arr2, ..., arrN) Arguments arrN โ€” N arrays from which to make the new array. Array(T) Returned value Returns an array with distinct elements from the source arrays Array(T) Examples Usage example sql title=Query SELECT arrayUnion([-2, 1], [10, 1], [-2], []) as num_example, arrayUnion(['hi'], [], ['hello', 'hi']) as str_example, arrayUnion([1, 3, NULL], [2, 3, NULL]) as null_example response title=Response โ”Œโ”€num_exampleโ”€โ”ฌโ”€str_exampleโ”€โ”€โ”€โ”€โ”ฌโ”€null_exampleโ”€โ” โ”‚ [10,-2,1] โ”‚ ['hello','hi'] โ”‚ [3,2,1,NULL] โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ arrayUniq {#arrayUniq} Introduced in: v1.1
{"source_file": "array-functions.md"}
[ -0.006043261848390102, -0.009468687698245049, -0.06253598630428314, -0.030694512650370598, -0.008730790577828884, -0.07195775955915451, 0.11770151555538177, -0.0958593487739563, -0.00674217427149415, -0.04695398360490799, -0.07275641709566116, 0.023964041844010353, 0.012562369927763939, -0...
a27282d6-3824-4f72-9eca-49606c39e924
arrayUniq {#arrayUniq} Introduced in: v1.1 For a single argument passed, counts the number of different elements in the array. For multiple arguments passed, it counts the number of different tuples made of elements at matching positions across multiple arrays. For example SELECT arrayUniq([1,2], [3,4], [5,6]) will form the following tuples: * Position 1: (1,3,5) * Position 2: (2,4,6) It will then count the number of unique tuples. In this case 2 . All arrays passed must have the same length. :::tip If you want to get a list of unique items in an array, you can use arrayReduce('groupUniqArray', arr) . ::: Syntax sql arrayUniq(arr1[, arr2, ..., arrN]) Arguments arr1 โ€” Array for which to count the number of unique elements. Array(T) [, arr2, ..., arrN] โ€” Optional. Additional arrays used to count the number of unique tuples of elements at corresponding positions in multiple arrays. Array(T) Returned value For a single argument returns the number of unique elements. For multiple arguments returns the number of unique tuples made from elements at corresponding positions across the arrays. UInt32 Examples Single argument sql title=Query SELECT arrayUniq([1, 1, 2, 2]) response title=Response 2 Multiple argument sql title=Query SELECT arrayUniq([1, 2, 3, 1], [4, 5, 6, 4]) response title=Response 3 arrayWithConstant {#arrayWithConstant} Introduced in: v20.1 Creates an array of length length filled with the constant x . Syntax sql arrayWithConstant(N, x) Arguments length โ€” Number of elements in the array. (U)Int* x โ€” The value of the N elements in the array, of any type. Returned value Returns an Array with N elements of value x . Array(T) Examples Usage example sql title=Query SELECT arrayWithConstant(3, 1) response title=Response [1, 1, 1] arrayZip {#arrayZip} Introduced in: v20.1 Combines multiple arrays into a single array. The resulting array contains the corresponding elements of the source arrays grouped into tuples in the listed order of arguments. Syntax sql arrayZip(arr1, arr2, ... , arrN) Arguments arr1, arr2, ... , arrN โ€” N arrays to combine into a single array. Array(T) Returned value Returns an array with elements from the source arrays grouped in tuples. Data types in the tuple are the same as types of the input arrays and in the same order as arrays are passed Array(T) Examples Usage example sql title=Query SELECT arrayZip(['a', 'b', 'c'], [5, 2, 1]); response title=Response [('a', 5), ('b', 2), ('c', 1)] arrayZipUnaligned {#arrayZipUnaligned} Introduced in: v20.1 Combines multiple arrays into a single array, allowing for unaligned arrays (arrays of differing lengths). The resulting array contains the corresponding elements of the source arrays grouped into tuples in the listed order of arguments. Syntax sql arrayZipUnaligned(arr1, arr2, ..., arrN) Arguments
{"source_file": "array-functions.md"}
[ 0.07292160391807556, -0.06776890158653259, -0.072486013174057, -0.026217211037874222, -0.01297375001013279, -0.0017471503233537078, 0.09896805882453918, -0.06502124667167664, -0.04918304458260536, -0.044919438660144806, -0.0429699644446373, 0.07331134378910065, 0.05598526820540428, -0.0390...
7f5d3e52-07af-477d-9bdc-7a04d5c4aceb
Syntax sql arrayZipUnaligned(arr1, arr2, ..., arrN) Arguments arr1, arr2, ..., arrN โ€” N arrays to combine into a single array. Array(T) Returned value Returns an array with elements from the source arrays grouped in tuples. Data types in the tuple are the same as types of the input arrays and in the same order as arrays are passed. Array(T) or Tuple(T1, T2, ...) Examples Usage example sql title=Query SELECT arrayZipUnaligned(['a'], [1, 2, 3]); response title=Response [('a', 1),(NULL, 2),(NULL, 3)] countEqual {#countEqual} Introduced in: v1.1 Returns the number of elements in the array equal to x . Equivalent to arrayCount(elem -> elem = x, arr) . NULL elements are handled as separate values. Syntax sql countEqual(arr, x) Arguments arr โ€” Array to search. Array(T) x โ€” Value in the array to count. Any type. Returned value Returns the number of elements in the array equal to x UInt64 Examples Usage example sql title=Query SELECT countEqual([1, 2, NULL, NULL], NULL) response title=Response 2 empty {#empty} Introduced in: v1.1 Checks whether the input array is empty. An array is considered empty if it does not contain any elements. :::note Can be optimized by enabling the optimize_functions_to_subcolumns setting . With optimize_functions_to_subcolumns = 1 the function reads only size0 subcolumn instead of reading and processing the whole array column. The query SELECT empty(arr) FROM TABLE; transforms to SELECT arr.size0 = 0 FROM TABLE; . ::: The function also works for Strings or UUIDs. Syntax sql empty(arr) Arguments arr โ€” Input array. Array(T) Returned value Returns 1 for an empty array or 0 for a non-empty array UInt8 Examples Usage example sql title=Query SELECT empty([]); response title=Response 1 emptyArrayDate {#emptyArrayDate} Introduced in: v1.1 Returns an empty Date array Syntax sql emptyArrayDate() Arguments None. Returned value An empty Date array. Array(T) Examples Usage example sql title=Query SELECT emptyArrayDate response title=Response [] emptyArrayDateTime {#emptyArrayDateTime} Introduced in: v1.1 Returns an empty DateTime array Syntax sql emptyArrayDateTime() Arguments None. Returned value An empty DateTime array. Array(T) Examples Usage example sql title=Query SELECT emptyArrayDateTime response title=Response [] emptyArrayFloat32 {#emptyArrayFloat32} Introduced in: v1.1 Returns an empty Float32 array Syntax sql emptyArrayFloat32() Arguments None. Returned value An empty Float32 array. Array(T) Examples Usage example sql title=Query SELECT emptyArrayFloat32 response title=Response [] emptyArrayFloat64 {#emptyArrayFloat64} Introduced in: v1.1 Returns an empty Float64 array Syntax sql emptyArrayFloat64() Arguments None. Returned value An empty Float64 array. Array(T) Examples Usage example
{"source_file": "array-functions.md"}
[ 0.05449783802032471, -0.036359239369630814, -0.06734656542539597, 0.04940720647573471, -0.09876697510480881, -0.02262970805168152, 0.09042544662952423, -0.06368304044008255, -0.04956074804067612, -0.04112006351351738, -0.05944124609231949, 0.053652048110961914, 0.10598427802324295, -0.0748...
f1cb4be3-af99-4029-b332-ed43097d0cb2
Introduced in: v1.1 Returns an empty Float64 array Syntax sql emptyArrayFloat64() Arguments None. Returned value An empty Float64 array. Array(T) Examples Usage example sql title=Query SELECT emptyArrayFloat64 response title=Response [] emptyArrayInt16 {#emptyArrayInt16} Introduced in: v1.1 Returns an empty Int16 array Syntax sql emptyArrayInt16() Arguments None. Returned value An empty Int16 array. Array(T) Examples Usage example sql title=Query SELECT emptyArrayInt16 response title=Response [] emptyArrayInt32 {#emptyArrayInt32} Introduced in: v1.1 Returns an empty Int32 array Syntax sql emptyArrayInt32() Arguments None. Returned value An empty Int32 array. Array(T) Examples Usage example sql title=Query SELECT emptyArrayInt32 response title=Response [] emptyArrayInt64 {#emptyArrayInt64} Introduced in: v1.1 Returns an empty Int64 array Syntax sql emptyArrayInt64() Arguments None. Returned value An empty Int64 array. Array(T) Examples Usage example sql title=Query SELECT emptyArrayInt64 response title=Response [] emptyArrayInt8 {#emptyArrayInt8} Introduced in: v1.1 Returns an empty Int8 array Syntax sql emptyArrayInt8() Arguments None. Returned value An empty Int8 array. Array(T) Examples Usage example sql title=Query SELECT emptyArrayInt8 response title=Response [] emptyArrayString {#emptyArrayString} Introduced in: v1.1 Returns an empty String array Syntax sql emptyArrayString() Arguments None. Returned value An empty String array. Array(T) Examples Usage example sql title=Query SELECT emptyArrayString response title=Response [] emptyArrayToSingle {#emptyArrayToSingle} Introduced in: v1.1 Accepts an empty array and returns a one-element array that is equal to the default value. Syntax sql emptyArrayToSingle(arr) Arguments arr โ€” An empty array. Array(T) Returned value An array with a single value of the Array's default type. Array(T) Examples Basic example ```sql title=Query CREATE TABLE test ( a Array(Int32), b Array(String), c Array(DateTime) ) ENGINE = MergeTree ORDER BY tuple(); INSERT INTO test VALUES ([], [], []); SELECT emptyArrayToSingle(a), emptyArrayToSingle(b), emptyArrayToSingle(c) FROM test; ``` response title=Response โ”Œโ”€emptyArrayToSingle(a)โ”€โ”ฌโ”€emptyArrayToSingle(b)โ”€โ”ฌโ”€emptyArrayToSingle(c)โ”€โ”€โ”€โ” โ”‚ [0] โ”‚ [''] โ”‚ ['1970-01-01 01:00:00'] โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ emptyArrayUInt16 {#emptyArrayUInt16} Introduced in: v1.1 Returns an empty UInt16 array Syntax sql emptyArrayUInt16() Arguments None. Returned value An empty UInt16 array. Array(T) Examples Usage example sql title=Query SELECT emptyArrayUInt16 response title=Response [] emptyArrayUInt32 {#emptyArrayUInt32} Introduced in: v1.1
{"source_file": "array-functions.md"}
[ 0.02806158736348152, 0.0374269112944603, -0.07732110470533371, 0.05148366838693619, -0.03653125464916229, -0.07441508769989014, 0.014060511253774166, -0.026128560304641724, 0.050842151045799255, -0.049314405769109726, -0.014066142030060291, -0.007418802939355373, -0.015351309441030025, -0....
5f5e120b-facf-41bc-9459-d593c39068a8
An empty UInt16 array. Array(T) Examples Usage example sql title=Query SELECT emptyArrayUInt16 response title=Response [] emptyArrayUInt32 {#emptyArrayUInt32} Introduced in: v1.1 Returns an empty UInt32 array Syntax sql emptyArrayUInt32() Arguments None. Returned value An empty UInt32 array. Array(T) Examples Usage example sql title=Query SELECT emptyArrayUInt32 response title=Response [] emptyArrayUInt64 {#emptyArrayUInt64} Introduced in: v1.1 Returns an empty UInt64 array Syntax sql emptyArrayUInt64() Arguments None. Returned value An empty UInt64 array. Array(T) Examples Usage example sql title=Query SELECT emptyArrayUInt64 response title=Response [] emptyArrayUInt8 {#emptyArrayUInt8} Introduced in: v1.1 Returns an empty UInt8 array Syntax sql emptyArrayUInt8() Arguments None. Returned value An empty UInt8 array. Array(T) Examples Usage example sql title=Query SELECT emptyArrayUInt8 response title=Response [] has {#has} Introduced in: v1.1 Returns whether the array contains the specified element. Syntax sql has(arr, x) Arguments arr โ€” The source array. Array(T) x โ€” The value to search for in the array. Returned value Returns 1 if the array contains the specified element, otherwise 0 . UInt8 Examples Basic usage sql title=Query SELECT has([1, 2, 3], 2) response title=Response 1 Not found sql title=Query SELECT has([1, 2, 3], 4) response title=Response 0 hasAll {#hasAll} Introduced in: v1.1 Checks whether one array is a subset of another. An empty array is a subset of any array. Null is processed as a value. The order of values in both the arrays does not matter. Syntax sql hasAll(set, subset) Arguments set โ€” Array of any type with a set of elements. Array(T) subset โ€” Array of any type that shares a common supertype with set containing elements that should be tested to be a subset of set . Array(T) Returned value 1 , if set contains all of the elements from subset . 0 , otherwise. Raises a NO_COMMON_TYPE exception if the set and subset elements do not share a common supertype. Examples Empty arrays sql title=Query SELECT hasAll([], []) response title=Response 1 Arrays containing NULL values sql title=Query SELECT hasAll([1, Null], [Null]) response title=Response 1 Arrays containing values of a different type sql title=Query SELECT hasAll([1.0, 2, 3, 4], [1, 3]) response title=Response 1 Arrays containing String values sql title=Query SELECT hasAll(['a', 'b'], ['a']) response title=Response 1 Arrays without a common type sql title=Query SELECT hasAll([1], ['a']) response title=Response Raises a NO_COMMON_TYPE exception Array of arrays sql title=Query SELECT hasAll([[1, 2], [3, 4]], [[1, 2], [3, 5]]) response title=Response 0 hasAny {#hasAny} Introduced in: v1.1
{"source_file": "array-functions.md"}
[ 0.0440620519220829, 0.043797124177217484, -0.08413979411125183, 0.05587585270404816, -0.08488763868808746, -0.07257705926895142, 0.002384516876190901, -0.037281155586242676, 0.06681840866804123, -0.04625525325536728, -0.028301671147346497, -0.008923446759581566, -0.038050130009651184, -0.0...
f6d1dd04-b752-4b9f-a813-681b109dc280
Array of arrays sql title=Query SELECT hasAll([[1, 2], [3, 4]], [[1, 2], [3, 5]]) response title=Response 0 hasAny {#hasAny} Introduced in: v1.1 Checks whether two arrays have intersection by some elements. Null is processed as a value. The order of the values in both of the arrays does not matter. Syntax sql hasAny(arr_x, arr_y) Arguments arr_x โ€” Array of any type with a set of elements. Array(T) arr_y โ€” Array of any type that shares a common supertype with array arr_x . Array(T) Returned value 1 , if arr_x and arr_y have one similar element at least. 0 , otherwise. Raises a NO_COMMON_TYPE exception if any of the elements of the two arrays do not share a common supertype. Examples One array is empty sql title=Query SELECT hasAny([1], []) response title=Response 0 Arrays containing NULL values sql title=Query SELECT hasAny([Null], [Null, 1]) response title=Response 1 Arrays containing values of a different type sql title=Query SELECT hasAny([-128, 1., 512], [1]) response title=Response 1 Arrays without a common type sql title=Query SELECT hasAny([[1, 2], [3, 4]], ['a', 'c']) response title=Response Raises a `NO_COMMON_TYPE` exception Array of arrays sql title=Query SELECT hasAll([[1, 2], [3, 4]], [[1, 2], [1, 2]]) response title=Response 1 hasSubstr {#hasSubstr} Introduced in: v20.6 Checks whether all the elements of array2 appear in a array1 in the same exact order. Therefore, the function will return 1 , if and only if array1 = prefix + array2 + suffix. In other words, the functions will check whether all the elements of array2 are contained in array1 like the hasAll function. In addition, it will check that the elements are observed in the same order in both array1 and array2. The function will return 1 if array2 is empty. Null is processed as a value. In other words hasSubstr([1, 2, NULL, 3, 4], [2,3]) will return 0 . However, hasSubstr([1, 2, NULL, 3, 4], [2,NULL,3]) will return 1 The order of values in both the arrays does matter. Raises a NO_COMMON_TYPE exception if any of the elements of the two arrays do not share a common supertype. Syntax sql hasSubstr(arr1, arr2) Arguments arr1 โ€” Array of any type with a set of elements. Array(T) arr2 โ€” Array of any type with a set of elements. Array(T) Returned value Returns 1 if array arr1 contains array arr2 . Otherwise, returns 0 . UInt8 Examples Both arrays are empty sql title=Query SELECT hasSubstr([], []) response title=Response 1 Arrays containing NULL values sql title=Query SELECT hasSubstr([1, Null], [Null]) response title=Response 1 Arrays containing values of a different type sql title=Query SELECT hasSubstr([1.0, 2, 3, 4], [1, 3]) response title=Response 0 Arrays containing strings sql title=Query SELECT hasSubstr(['a', 'b'], ['a']) response title=Response 1 Arrays with valid ordering
{"source_file": "array-functions.md"}
[ 0.06884247064590454, -0.005457001738250256, -0.035911574959754944, -0.011742324568331242, 0.020666178315877914, -0.0887940376996994, 0.09500554949045181, -0.08568970113992691, -0.06967340409755707, -0.050852470099925995, -0.02383609488606453, 0.03803233429789543, 0.006899844389408827, -0.0...
eb4c757f-ad76-4e90-adb8-de0f9aa83eb1
response title=Response 0 Arrays containing strings sql title=Query SELECT hasSubstr(['a', 'b'], ['a']) response title=Response 1 Arrays with valid ordering sql title=Query SELECT hasSubstr(['a', 'b' , 'c'], ['a', 'b']) response title=Response 1 Arrays with invalid ordering sql title=Query SELECT hasSubstr(['a', 'b' , 'c'], ['a', 'c']) response title=Response 0 Array of arrays sql title=Query SELECT hasSubstr([[1, 2], [3, 4], [5, 6]], [[1, 2], [3, 4]]) response title=Response 1 Arrays without a common type sql title=Query SELECT hasSubstr([1, 2, NULL, 3, 4], ['a']) response title=Response Raises a `NO_COMMON_TYPE` exception indexOf {#indexOf} Introduced in: v1.1 Returns the index of the first element with value 'x' (starting from 1) if it is in the array. If the array does not contain the searched-for value, the function returns 0 . Elements set to NULL are handled as normal values. Syntax sql indexOf(arr, x) Arguments arr โ€” An array to search in for x . Array(T) x โ€” Value of the first matching element in arr for which to return an index. UInt64 Returned value Returns the index (numbered from one) of the first x in arr if it exists. Otherwise, returns 0 . UInt64 Examples Basic example sql title=Query SELECT indexOf([5, 4, 1, 3], 3) response title=Response 4 Array with nulls sql title=Query SELECT indexOf([1, 3, NULL, NULL], NULL) response title=Response 3 indexOfAssumeSorted {#indexOfAssumeSorted} Introduced in: v24.12 Returns the index of the first element with value 'x' (starting from 1 ) if it is in the array. If the array does not contain the searched-for value, the function returns 0 . :::note Unlike the indexOf function, this function assumes that the array is sorted in ascending order. If the array is not sorted, results are undefined. ::: Syntax sql indexOfAssumeSorted(arr, x) Arguments arr โ€” A sorted array to search. Array(T) x โ€” Value of the first matching element in sorted arr for which to return an index. UInt64 Returned value Returns the index (numbered from one) of the first x in arr if it exists. Otherwise, returns 0 . UInt64 Examples Basic example sql title=Query SELECT indexOfAssumeSorted([1, 3, 3, 3, 4, 4, 5], 4) response title=Response 5 length {#length} Introduced in: v1.1 Calculates the length of a string or array. For String or FixedString arguments: calculates the number of bytes in the string. For Array arguments: calculates the number of elements in the array. If applied to a FixedString argument, the function is a constant expression. Please note that the number of bytes in a string is not the same as the number of Unicode "code points" and it is not the same as the number of Unicode "grapheme clusters" (what we usually call "characters") and it is not the same as the visible string width.
{"source_file": "array-functions.md"}
[ 0.03312487527728081, -0.006583437789231539, 0.03442615643143654, 0.00807199813425541, -0.0076174428686499596, -0.005581013858318329, 0.005241639446467161, -0.07760942727327347, -0.07396863400936127, 0.005105113610625267, -0.06157997250556946, 0.02394685707986355, 0.042854394763708115, -0.0...
1d180c82-c9aa-4d4c-87ea-c5d1c00f864b
It is ok to have ASCII NULL bytes in strings, and they will be counted as well. Syntax sql length(x) Aliases : OCTET_LENGTH Arguments x โ€” Value for which to calculate the number of bytes (for String/FixedString) or elements (for Array). String or FixedString or Array(T) Returned value Returns the number of number of bytes in the String/FixedString x / the number of elements in array x UInt64 Examples String example sql title=Query SELECT length('Hello, world!') response title=Response 13 Array example sql title=Query SELECT length(['Hello', 'world']) response title=Response 2 constexpr example sql title=Query WITH 'hello' || toString(number) AS str SELECT str, isConstant(length(str)) AS str_length_is_constant, isConstant(length(str::FixedString(6))) AS fixed_str_length_is_constant FROM numbers(3) response title=Response โ”Œโ”€strโ”€โ”€โ”€โ”€โ”ฌโ”€str_length_is_constantโ”€โ”ฌโ”€fixed_str_length_is_constantโ”€โ” โ”‚ hello0 โ”‚ 0 โ”‚ 1 โ”‚ โ”‚ hello1 โ”‚ 0 โ”‚ 1 โ”‚ โ”‚ hello2 โ”‚ 0 โ”‚ 1 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ unicode example sql title=Query SELECT 'ั‘ะปะบะฐ' AS str1, length(str1), lengthUTF8(str1), normalizeUTF8NFKD(str1) AS str2, length(str2), lengthUTF8(str2) response title=Response โ”Œโ”€str1โ”€โ”ฌโ”€length(str1)โ”€โ”ฌโ”€lengthUTF8(str1)โ”€โ”ฌโ”€str2โ”€โ”ฌโ”€length(str2)โ”€โ”ฌโ”€lengthUTF8(str2)โ”€โ” โ”‚ ั‘ะปะบะฐ โ”‚ 8 โ”‚ 4 โ”‚ ะตฬˆะปะบะฐ โ”‚ 10 โ”‚ 5 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ascii_vs_utf8 example sql title=Query SELECT 'รกbc' AS str, length(str), lengthUTF8(str) response title=Response โ”Œโ”€strโ”€โ”ฌโ”€length(str)โ”€โ”€โ”ฌโ”€lengthUTF8(str)โ”€โ” โ”‚ รกbc โ”‚ 4 โ”‚ 3 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ notEmpty {#notEmpty} Introduced in: v1.1 Checks whether the input array is non-empty. An array is considered non-empty if it contains at least one element. :::note Can be optimized by enabling the optimize_functions_to_subcolumns setting. With optimize_functions_to_subcolumns = 1 the function reads only size0 subcolumn instead of reading and processing the whole array column. The query SELECT notEmpty(arr) FROM table transforms to SELECT arr.size0 != 0 FROM TABLE . ::: The function also works for Strings or UUIDs. Syntax sql notEmpty(arr) Arguments arr โ€” Input array. Array(T) Returned value Returns 1 for a non-empty array or 0 for an empty array UInt8 Examples Usage example sql title=Query SELECT notEmpty([1,2]); response title=Response 1 range {#range} Introduced in: v1.1 Returns an array of numbers from start to end - 1 by step . The supported types are: - UInt8/16/32/64 - Int8/16/32/64]
{"source_file": "array-functions.md"}
[ 0.027053313329815865, 0.025565801188349724, -0.05945616215467453, 0.005404292605817318, -0.1293727606534958, -0.03430957719683647, 0.056310608983039856, 0.07177522033452988, -0.039339806884527206, -0.030246993526816368, -0.02951914444565773, -0.057228561490774155, 0.07304897904396057, -0.0...
7fd09537-1175-4a0e-80ec-fc358870f513
response title=Response 1 range {#range} Introduced in: v1.1 Returns an array of numbers from start to end - 1 by step . The supported types are: - UInt8/16/32/64 - Int8/16/32/64] All arguments start , end , step must be one of the above supported types. Elements of the returned array will be a super type of the arguments. An exception is thrown if the function returns an array with a total length more than the number of elements specified by setting function_range_max_elements_in_block . Returns NULL if any argument has Nullable(nothing) type. An exception is thrown if any argument has NULL value (Nullable(T) type). Syntax sql range([start, ] end [, step]) Arguments start โ€” Optional. The first element of the array. Required if step is used. Default value: 0 . - end โ€” Required. The number before which the array is constructed. - step โ€” Optional. Determines the incremental step between each element in the array. Default value: 1 . Returned value Array of numbers from start to end - 1 by step . Array(T) Examples Usage example sql title=Query SELECT range(5), range(1, 5), range(1, 5, 2), range(-1, 5, 2); response title=Response โ”Œโ”€range(5)โ”€โ”€โ”€โ”€โ”ฌโ”€range(1, 5)โ”€โ”ฌโ”€range(1, 5, 2)โ”€โ”ฌโ”€range(-1, 5, 2)โ”€โ” โ”‚ [0,1,2,3,4] โ”‚ [1,2,3,4] โ”‚ [1,3] โ”‚ [-1,1,3] โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ replicate {#replicate} Introduced in: v1.1 Creates an array with a single value. Syntax sql replicate(x, arr) Arguments x โ€” The value to fill the result array with. Any arr โ€” An array. Array(T) Returned value Returns an array of the same length as arr filled with value x . Array(T) Examples Usage example sql title=Query SELECT replicate(1, ['a', 'b', 'c']); response title=Response โ”Œโ”€replicate(1, ['a', 'b', 'c'])โ”€โ”€โ”€โ” โ”‚ [1, 1, 1] โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ reverse {#reverse} Introduced in: v1.1 Reverses the order of the elements in the input array or the characters in the input string. Syntax sql reverse(arr | str) Arguments arr | str โ€” The source array or string. Array(T) or String Returned value Returns an array or string with the order of elements or characters reversed. Examples Reverse array sql title=Query SELECT reverse([1, 2, 3, 4]); response title=Response [4, 3, 2, 1] Reverse string sql title=Query SELECT reverse('abcd'); response title=Response 'dcba' Distance functions {#distance-functions} All supported functions are described in distance functions documentation .
{"source_file": "array-functions.md"}
[ 0.002141076372936368, 0.02253662422299385, -0.04938112571835518, 0.014492972753942013, -0.1009405106306076, 0.00042239250615239143, -0.000840582069940865, 0.0632336214184761, -0.05947251617908478, -0.06751414388418198, -0.041036006063222885, 0.0026962219271808863, 0.03057112917304039, -0.0...
0de6f360-b489-4336-b286-cee797202db2
description: 'Documentation for string functions' sidebar_label: 'String' slug: /sql-reference/functions/string-functions title: 'Functions for working with strings' doc_type: 'reference' import VersionBadge from '@theme/badges/VersionBadge'; Functions for working with strings Functions for searching in strings and for replacing in strings are described separately. :::note The documentation below is generated from the system.functions system table. ::: CRC32 {#CRC32} Introduced in: v20.1 Calculates the CRC32 checksum of a string using the CRC-32-IEEE 802.3 polynomial and initial value 0xffffffff (zlib implementation). Syntax sql CRC32(s) Arguments s โ€” String to calculate CRC32 for. String Returned value Returns the CRC32 checksum of the string. UInt32 Examples Usage example sql title=Query SELECT CRC32('ClickHouse') response title=Response โ”Œโ”€CRC32('ClickHouse')โ”€โ” โ”‚ 1538217360 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ CRC32IEEE {#CRC32IEEE} Introduced in: v20.1 Calculates the CRC32 checksum of a string using the CRC-32-IEEE 802.3 polynomial. Syntax sql CRC32IEEE(s) Arguments s โ€” String to calculate CRC32 for. String Returned value Returns the CRC32 checksum of the string. UInt32 Examples Usage example sql title=Query SELECT CRC32IEEE('ClickHouse'); response title=Response โ”Œโ”€CRC32IEEE('ClickHouse')โ”€โ” โ”‚ 3089448422 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ CRC64 {#CRC64} Introduced in: v20.1 Calculates the CRC64 checksum of a string using the CRC-64-ECMA polynomial. Syntax sql CRC64(s) Arguments s โ€” String to calculate CRC64 for. String Returned value Returns the CRC64 checksum of the string. UInt64 Examples Usage example sql title=Query SELECT CRC64('ClickHouse'); response title=Response โ”Œโ”€โ”€CRC64('ClickHouse')โ”€โ” โ”‚ 12126588151325169346 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ appendTrailingCharIfAbsent {#appendTrailingCharIfAbsent} Introduced in: v1.1 Appends character c to string s if s is non-empty and does not end with character c . Syntax sql appendTrailingCharIfAbsent(s, c) Arguments s โ€” Input string. String c โ€” Character to append if absent. String Returned value Returns string s with character c appended if s does not end with c . String Examples Usage example sql title=Query SELECT appendTrailingCharIfAbsent('https://example.com', '/'); response title=Response โ”Œโ”€appendTrailiโ‹ฏ.com', '/')โ”€โ” โ”‚ https://example.com/ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ascii {#ascii} Introduced in: v22.11 Returns the ASCII code point of the first character of string s as an Int32 . Syntax sql ascii(s) Arguments s โ€” String input. String Returned value Returns the ASCII code point of the first character. If s is empty, the result is 0 . If the first character is not an ASCII character or not part of the Latin-1 supplement range of UTF-16, the result is undefined. Int32 Examples
{"source_file": "string-functions.md"}
[ -0.021323395892977715, 0.05024566128849983, -0.06466507166624069, 0.004841926041990519, -0.03795613721013069, -0.01309728343039751, 0.0751458927989006, 0.06048635020852089, -0.044831059873104095, -0.006219749804586172, 0.012793260626494884, -0.09554380923509598, 0.10060476511716843, -0.070...
2e825775-eac6-4589-9e4e-e18fd6fe6ab6
Examples Usage example sql title=Query SELECT ascii('234') response title=Response โ”Œโ”€ascii('234')โ”€โ” โ”‚ 50 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ base32Decode {#base32Decode} Introduced in: v25.6 Decodes a Base32 (RFC 4648) string. If the string is not valid Base32-encoded, an exception is thrown. Syntax sql base32Decode(encoded) Arguments encoded โ€” String column or constant. String Returned value Returns a string containing the decoded value of the argument. String Examples Usage example sql title=Query SELECT base32Decode('IVXGG33EMVSA===='); response title=Response โ”Œโ”€base32Decode('IVXGG33EMVSA====')โ”€โ” โ”‚ Encoded โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ base32Encode {#base32Encode} Introduced in: v25.6 Encodes a string using Base32 . Syntax sql base32Encode(plaintext) Arguments plaintext โ€” Plaintext to encode. String Returned value Returns a string containing the encoded value of the argument. String or FixedString Examples Usage example sql title=Query SELECT base32Encode('Encoded') response title=Response โ”Œโ”€base32Encode('Encoded')โ”€โ” โ”‚ IVXGG33EMVSA==== โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ base58Decode {#base58Decode} Introduced in: v22.7 Decodes a Base58 string. If the string is not valid Base58-encoded, an exception is thrown. Syntax sql base58Decode(encoded) Arguments encoded โ€” String column or constant to decode. String Returned value Returns a string containing the decoded value of the argument. String Examples Usage example sql title=Query SELECT base58Decode('JxF12TrwUP45BMd'); response title=Response โ”Œโ”€base58Decodeโ‹ฏrwUP45BMd')โ”€โ” โ”‚ Hello World โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ base58Encode {#base58Encode} Introduced in: v22.7 Encodes a string using Base58 encoding. Syntax sql base58Encode(plaintext) Arguments plaintext โ€” Plaintext to encode. String Returned value Returns a string containing the encoded value of the argument. String Examples Usage example sql title=Query SELECT base58Encode('ClickHouse'); response title=Response โ”Œโ”€base58Encode('ClickHouse')โ”€โ” โ”‚ 4nhk8K7GHXf6zx โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ base64Decode {#base64Decode} Introduced in: v18.16 Decodes a string from Base64 representation, according to RFC 4648. Throws an exception in case of error. Syntax sql base64Decode(encoded) Aliases : FROM_BASE64 Arguments encoded โ€” String column or constant to decode. If the string is not valid Base64-encoded, an exception is thrown. String Returned value Returns the decoded string. String Examples Usage example sql title=Query SELECT base64Decode('Y2xpY2tob3VzZQ==') response title=Response โ”Œโ”€base64Decode('Y2xpY2tob3VzZQ==')โ”€โ” โ”‚ clickhouse โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ base64Encode {#base64Encode} Introduced in: v18.16
{"source_file": "string-functions.md"}
[ 0.018250619992613792, -0.01941267028450966, -0.038960233330726624, 0.015398718416690826, -0.07416949421167374, -0.017762640491127968, 0.02534313127398491, 0.035004258155822754, -0.0038309937808662653, -0.02121927961707115, -0.056822776794433594, -0.07911702990531921, 0.05544121563434601, -...
2c2f9641-a3a4-4da1-8d8c-5b2d05250200
response title=Response โ”Œโ”€base64Decode('Y2xpY2tob3VzZQ==')โ”€โ” โ”‚ clickhouse โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ base64Encode {#base64Encode} Introduced in: v18.16 Encodes a string using Base64 representation, according to RFC 4648. Syntax sql base64Encode(plaintext) Aliases : TO_BASE64 Arguments plaintext โ€” Plaintext column or constant to decode. String Returned value Returns a string containing the encoded value of the argument. String Examples Usage example sql title=Query SELECT base64Encode('clickhouse') response title=Response โ”Œโ”€base64Encode('clickhouse')โ”€โ” โ”‚ Y2xpY2tob3VzZQ== โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ base64URLDecode {#base64URLDecode} Introduced in: v24.6 Decodes a string from Base64 representation using URL-safe alphabet, according to RFC 4648. Throws an exception in case of error. Syntax sql base64URLDecode(encoded) Arguments encoded โ€” String column or constant to encode. If the string is not valid Base64-encoded, an exception is thrown. String Returned value Returns a string containing the decoded value of the argument. String Examples Usage example sql title=Query SELECT base64URLDecode('aHR0cHM6Ly9jbGlja2hvdXNlLmNvbQ') response title=Response โ”Œโ”€base64URLDecode('aHR0cHM6Ly9jbGlja2hvdXNlLmNvbQ')โ”€โ” โ”‚ https://clickhouse.com โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ base64URLEncode {#base64URLEncode} Introduced in: v18.16 Encodes a string using Base64 (RFC 4648) representation using URL-safe alphabet. Syntax sql base64URLEncode(plaintext) Arguments plaintext โ€” Plaintext column or constant to encode. String Returned value Returns a string containing the encoded value of the argument. String Examples Usage example sql title=Query SELECT base64URLEncode('https://clickhouse.com') response title=Response โ”Œโ”€base64URLEncode('https://clickhouse.com')โ”€โ” โ”‚ aHR0cHM6Ly9jbGlja2hvdXNlLmNvbQ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ basename {#basename} Introduced in: v20.1 Extracts the tail of a string following its last slash or backslash. This function is often used to extract the filename from a path. Syntax sql basename(expr) Arguments expr โ€” A string expression. Backslashes must be escaped. String Returned value Returns the tail of the input string after its last slash or backslash. If the input string ends with a slash or backslash, the function returns an empty string. Returns the original string if there are no slashes or backslashes. String Examples Extract filename from Unix path sql title=Query SELECT 'some/long/path/to/file' AS a, basename(a) response title=Response โ”Œโ”€aโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€basename('some/long/path/to/file')โ”€โ” โ”‚ some/long/path/to/file โ”‚ file โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Extract filename from Windows path
{"source_file": "string-functions.md"}
[ 0.018808439373970032, -0.017086543142795563, -0.02640974521636963, 0.00001389141925756121, -0.06283295154571533, -0.022834278643131256, 0.005627134349197149, -0.0009270471637137234, -0.03359992802143097, -0.039307523518800735, -0.004748526960611343, -0.002183704636991024, 0.05429244041442871...
1751f9d2-50a4-445b-9a37-b4ee83128ca7
Extract filename from Windows path sql title=Query SELECT 'some\\long\\path\\to\\file' AS a, basename(a) response title=Response โ”Œโ”€aโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€basename('some\\long\\path\\to\\file')โ”€โ” โ”‚ some\long\path\to\file โ”‚ file โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ String with no path separators sql title=Query SELECT 'some-file-name' AS a, basename(a) response title=Response โ”Œโ”€aโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€basename('some-file-name')โ”€โ” โ”‚ some-file-name โ”‚ some-file-name โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ byteHammingDistance {#byteHammingDistance} Introduced in: v23.9 Calculates the hamming distance between two byte strings. Syntax sql byteHammingDistance(s1, s2) Aliases : mismatches Arguments s1 โ€” First input string. String s2 โ€” Second input string. String Returned value Returns the Hamming distance between the two strings. UInt64 Examples Usage example sql title=Query SELECT byteHammingDistance('karolin', 'kathrin') response title=Response โ”Œโ”€byteHammingDistance('karolin', 'kathrin')โ”€โ” โ”‚ 3 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ compareSubstrings {#compareSubstrings} Introduced in: v25.2 Compares two strings lexicographically. Syntax sql compareSubstrings(s1, s2, s1_offset, s2_offset, num_bytes) Arguments s1 โ€” The first string to compare. String s2 โ€” The second string to compare. String s1_offset โ€” The position (zero-based) in s1 from which the comparison starts. UInt* s2_offset โ€” The position (zero-based index) in s2 from which the comparison starts. UInt* num_bytes โ€” The maximum number of bytes to compare in both strings. If s1_offset (or s2_offset ) + num_bytes exceeds the end of an input string, num_bytes will be reduced accordingly. UInt* Returned value Returns: - -1 if s1 [ s1_offset : s1_offset + num_bytes ] < s2 [ s2_offset : s2_offset + num_bytes ]. - 0 if s1 [ s1_offset : s1_offset + num_bytes ] = s2 [ s2_offset : s2_offset + num_bytes ]. - 1 if s1 [ s1_offset : s1_offset + num_bytes ] > s2 [ s2_offset : s2_offset + num_bytes ]. Int8 Examples Usage example sql title=Query SELECT compareSubstrings('Saxony', 'Anglo-Saxon', 0, 6, 5) AS result response title=Response โ”Œโ”€resultโ”€โ” โ”‚ 0 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ concat {#concat} Introduced in: v1.1 Concatenates the given arguments. Arguments which are not of types String or FixedString are converted to strings using their default serialization. As this decreases performance, it is not recommended to use non-String/FixedString arguments. Syntax sql concat([s1, s2, ...]) Arguments s1, s2, ... โ€” Any number of values of arbitrary type. Any Returned value
{"source_file": "string-functions.md"}
[ -0.03592844307422638, -0.02744229882955551, -0.023572523146867752, 0.015270917676389217, -0.08395234495401382, -0.036357954144477844, 0.07782337814569473, 0.0780576765537262, -0.016492202877998352, 0.0083469795063138, 0.027643274515867233, -0.03206929191946983, 0.06789109110832214, -0.0426...
02a3e472-2610-49ce-8f73-523966409166
Syntax sql concat([s1, s2, ...]) Arguments s1, s2, ... โ€” Any number of values of arbitrary type. Any Returned value Returns the String created by concatenating the arguments. If any of arguments is NULL , the function returns NULL . If there are no arguments, it returns an empty string. Nullable(String) Examples String concatenation sql title=Query SELECT concat('Hello, ', 'World!') response title=Response โ”Œโ”€concat('Hello, ', 'World!')โ”€โ” โ”‚ Hello, World! โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Number concatenation sql title=Query SELECT concat(42, 144) response title=Response โ”Œโ”€concat(42, 144)โ”€โ” โ”‚ 42144 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ concatAssumeInjective {#concatAssumeInjective} Introduced in: v1.1 Like concat but assumes that concat(s1, s2, ...) โ†’ sn is injective, i.e, it returns different results for different arguments. Can be used for optimization of GROUP BY . Syntax sql concatAssumeInjective([s1, s2, ...]) Arguments s1, s2, ... โ€” Any number of values of arbitrary type. String or FixedString Returned value Returns the string created by concatenating the arguments. If any of argument values is NULL , the function returns NULL . If no arguments are passed, it returns an empty string. String Examples Group by optimization sql title=Query SELECT concat(key1, key2), sum(value) FROM key_val GROUP BY concatAssumeInjective(key1, key2) response title=Response โ”Œโ”€concat(key1, key2)โ”€โ”ฌโ”€sum(value)โ”€โ” โ”‚ Hello, World! โ”‚ 3 โ”‚ โ”‚ Hello, World! โ”‚ 2 โ”‚ โ”‚ Hello, World โ”‚ 3 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ concatWithSeparator {#concatWithSeparator} Introduced in: v22.12 Concatenates the provided strings, separating them by the specified separator. Syntax sql concatWithSeparator(sep[, exp1, exp2, ...]) Aliases : concat_ws Arguments sep โ€” The separator to use. const String or const FixedString exp1, exp2, ... โ€” Expression to be concatenated. Arguments which are not of type String or FixedString are converted to strings using their default serialization. As this decreases performance, it is not recommended to use non-String/FixedString arguments. Any Returned value Returns the String created by concatenating the arguments. If any of the argument values is NULL , the function returns NULL . String Examples Usage example sql title=Query SELECT concatWithSeparator('a', '1', '2', '3', '4') response title=Response โ”Œโ”€concatWithSeparator('a', '1', '2', '3', '4')โ”€โ” โ”‚ 1a2a3a4 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ concatWithSeparatorAssumeInjective {#concatWithSeparatorAssumeInjective} Introduced in: v22.12 Like concatWithSeparator but assumes that concatWithSeparator(sep[,exp1, exp2, ... ]) โ†’ result is injective. A function is called injective if it returns different results for different arguments.
{"source_file": "string-functions.md"}
[ 0.031001824885606766, -0.009292318485677242, 0.009702605195343494, 0.04510406404733658, -0.0614614300429821, -0.051633320748806, 0.08569350093603134, -0.016416577622294426, -0.04979989305138588, -0.03998972102999687, 0.01738189533352852, -0.015170389786362648, 0.07564530521631241, -0.07820...
2ba32d5b-262c-4d9a-a45d-abf22024b25b
Can be used for optimization of GROUP BY . Syntax sql concatWithSeparatorAssumeInjective(sep[, exp1, exp2, ... ]) Arguments sep โ€” The separator to use. const String or const FixedString exp1, exp2, ... โ€” Expression to be concatenated. Arguments which are not of type String or FixedString are converted to strings using their default serialization. As this decreases performance, it is not recommended to use non-String/FixedString arguments. String or FixedString Returned value Returns the String created by concatenating the arguments. If any of the argument values is NULL , the function returns NULL . String Examples Usage example ```sql title=Query CREATE TABLE user_data ( user_id UInt32, first_name String, last_name String, score UInt32 ) ENGINE = MergeTree ORDER BY tuple(); INSERT INTO user_data VALUES (1, 'John', 'Doe', 100), (2, 'Jane', 'Smith', 150), (3, 'John', 'Wilson', 120), (4, 'Jane', 'Smith', 90); SELECT concatWithSeparatorAssumeInjective('-', first_name, last_name) as full_name, sum(score) as total_score FROM user_data GROUP BY concatWithSeparatorAssumeInjective('-', first_name, last_name); ``` response title=Response โ”Œโ”€full_nameโ”€โ”€โ”€โ”ฌโ”€total_scoreโ”€โ” โ”‚ Jane-Smith โ”‚ 240 โ”‚ โ”‚ John-Doe โ”‚ 100 โ”‚ โ”‚ John-Wilson โ”‚ 120 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ conv {#conv} Introduced in: v1.1 Converts numbers between different number bases. The function converts a number from one base to another. It supports bases from 2 to 36. For bases higher than 10, letters A-Z (case insensitive) are used to represent digits 10-35. This function is compatible with MySQL's CONV() function. Syntax sql conv(number, from_base, to_base) Arguments number โ€” The number to convert. Can be a string or numeric type. - from_base โ€” The source base (2-36). Must be an integer. - to_base โ€” The target base (2-36). Must be an integer. Returned value String representation of the number in the target base. Examples Convert decimal to binary sql title=Query SELECT conv('10', 10, 2) response title=Response 1010 Convert hexadecimal to decimal sql title=Query SELECT conv('FF', 16, 10) response title=Response 255 Convert with negative number sql title=Query SELECT conv('-1', 10, 16) response title=Response FFFFFFFFFFFFFFFF Convert binary to octal sql title=Query SELECT conv('1010', 2, 8) response title=Response 12 convertCharset {#convertCharset} Introduced in: v1.1 Returns string s converted from the encoding from to encoding to . Syntax sql convertCharset(s, from, to) Arguments s โ€” Input string. String from โ€” Source character encoding. String to โ€” Target character encoding. String Returned value Returns string s converted from encoding from to encoding to . String Examples Usage example sql title=Query SELECT convertCharset('Cafรฉ', 'UTF-8', 'ISO-8859-1');
{"source_file": "string-functions.md"}
[ 0.015623347833752632, 0.02015920728445053, 0.012734864838421345, 0.026256144046783447, -0.12172260880470276, -0.021778522059321404, 0.11708609759807587, 0.0638655498623848, -0.07301546633243561, -0.027810916304588318, 0.06214601546525955, -0.022540632635354996, 0.02333461120724678, -0.1185...
e66b3ad0-0f89-456b-abe9-c467f40e79c2
Returned value Returns string s converted from encoding from to encoding to . String Examples Usage example sql title=Query SELECT convertCharset('Cafรฉ', 'UTF-8', 'ISO-8859-1'); response title=Response โ”Œโ”€convertCharsโ‹ฏSO-8859-1')โ”€โ” โ”‚ Caf๏ฟฝ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ damerauLevenshteinDistance {#damerauLevenshteinDistance} Introduced in: v24.1 Calculates the Damerau-Levenshtein distance between two byte strings. Syntax sql damerauLevenshteinDistance(s1, s2) Arguments s1 โ€” First input string. String s2 โ€” Second input string. String Returned value Returns the Damerau-Levenshtein distance between the two strings. UInt64 Examples Usage example sql title=Query SELECT damerauLevenshteinDistance('clickhouse', 'mouse') response title=Response โ”Œโ”€damerauLevenshteinDistance('clickhouse', 'mouse')โ”€โ” โ”‚ 6 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ decodeHTMLComponent {#decodeHTMLComponent} Introduced in: v23.9 Decodes HTML entities in a string to their corresponding characters. Syntax sql decodeHTMLComponent(s) Arguments s โ€” String containing HTML entities to decode. String Returned value Returns the string with HTML entities decoded. String Examples Usage example sql title=Query SELECT decodeHTMLComponent('&lt;div&gt;Hello &amp; &quot;World&quot;&lt;/div&gt;') response title=Response โ”Œโ”€decodeHTMLComponent('&lt;div&gt;Hello &amp; &quot;World&quot;&lt;/div&gt;')โ”€โ” โ”‚ <div>Hello & "World"</div> โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ decodeXMLComponent {#decodeXMLComponent} Introduced in: v21.2 Decodes XML entities in a string to their corresponding characters. Syntax sql decodeXMLComponent(s) Arguments s โ€” String containing XML entities to decode. String Returned value Returns the provided string with XML entities decoded. String Examples Usage example sql title=Query SELECT decodeXMLComponent('&lt;tag&gt;Hello &amp; World&lt;/tag&gt;') response title=Response โ”Œโ”€decodeXMLComโ‹ฏ;/tag&gt;')โ”€โ” โ”‚ <tag>Hello & World</tag> โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ editDistance {#editDistance} Introduced in: v23.9 Calculates the edit distance between two byte strings. Syntax sql editDistance(s1, s2) Aliases : levenshteinDistance Arguments s1 โ€” First input string. String s2 โ€” Second input string. String Returned value Returns the edit distance between the two strings. UInt64 Examples Usage example sql title=Query SELECT editDistance('clickhouse', 'mouse') response title=Response โ”Œโ”€editDistance('clickhouse', 'mouse')โ”€โ” โ”‚ 6 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ editDistanceUTF8 {#editDistanceUTF8} Introduced in: v24.6 Calculates the edit distance between two UTF8 strings. Syntax
{"source_file": "string-functions.md"}
[ 0.027191638946533203, -0.05883374065160751, -0.03565848246216774, -0.02727370150387287, -0.07278130948543549, 0.01924435794353485, 0.0019395067356526852, 0.01894388720393181, 0.019967759028077126, -0.061663348227739334, 0.04395011067390442, -0.05276261270046234, 0.1281079649925232, -0.0638...
cff3b2fe-ee63-4cdf-a2cc-452f91afbd5d
editDistanceUTF8 {#editDistanceUTF8} Introduced in: v24.6 Calculates the edit distance between two UTF8 strings. Syntax sql editDistanceUTF8(s1, s2) Aliases : levenshteinDistanceUTF8 Arguments s1 โ€” First input string. String s2 โ€” Second input string. String Returned value Returns the edit distance between the two UTF8 strings. UInt64 Examples Usage example sql title=Query SELECT editDistanceUTF8('ๆˆ‘ๆ˜ฏ่ฐ', 'ๆˆ‘ๆ˜ฏๆˆ‘') response title=Response โ”Œโ”€editDistanceUTF8('ๆˆ‘ๆ˜ฏ่ฐ', 'ๆˆ‘ๆ˜ฏๆˆ‘')โ”€โ”€โ” โ”‚ 1 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ encodeXMLComponent {#encodeXMLComponent} Introduced in: v21.1 Escapes characters to place string into XML text node or attribute. Syntax sql encodeXMLComponent(s) Arguments s โ€” String to escape. String Returned value Returns the escaped string. String Examples Usage example sql title=Query SELECT '<tag>Hello & "World"</tag>' AS original, encodeXMLComponent('<tag>Hello & "World"</tag>') AS xml_encoded; response title=Response โ”Œโ”€originalโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€xml_encodedโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ <tag>Hello & "World"</tag> โ”‚ &lt;tag&gt;Hello &amp; &quot;World&quot;&lt;/tag&gt; โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ endsWith {#endsWith} Introduced in: v1.1 Checks whether a string ends with the provided suffix. Syntax sql endsWith(s, suffix) Arguments s โ€” String to check. String suffix โ€” Suffix to check for. String Returned value Returns 1 if s ends with suffix , otherwise 0 . UInt8 Examples Usage example sql title=Query SELECT endsWith('ClickHouse', 'House'); response title=Response โ”Œโ”€endsWith('Clโ‹ฏ', 'House')โ”€โ” โ”‚ 1 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ endsWithCaseInsensitive {#endsWithCaseInsensitive} Introduced in: v25.9 Checks whether a string ends with the provided case-insensitive suffix. Syntax sql endsWithCaseInsensitive(s, suffix) Arguments s โ€” String to check. String suffix โ€” Case-insensitive suffix to check for. String Returned value Returns 1 if s ends with case-insensitive suffix , otherwise 0 . UInt8 Examples Usage example sql title=Query SELECT endsWithCaseInsensitive('ClickHouse', 'HOUSE'); response title=Response โ”Œโ”€endsWithCaseInsensitive('Clโ‹ฏ', 'HOUSE')โ”€โ” โ”‚ 1 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ endsWithCaseInsensitiveUTF8 {#endsWithCaseInsensitiveUTF8} Introduced in: v25.9 Returns whether string s ends with case-insensitive suffix . Assumes that the string contains valid UTF-8 encoded text. If this assumption is violated, no exception is thrown and the result is undefined. Syntax sql endsWithCaseInsensitiveUTF8(s, suffix) Arguments s โ€” String to check. String suffix โ€” Case-insensitive suffix to check for. String Returned value
{"source_file": "string-functions.md"}
[ -0.025561079382896423, -0.030098939314484596, -0.016994697973132133, 0.01955106109380722, -0.11177506297826767, 0.07929665595293045, 0.006033672019839287, 0.08028725534677505, -0.015519308857619762, -0.002331563737243414, 0.0682559683918953, -0.07901506125926971, 0.10789402574300766, -0.08...
f78b631c-b069-4fe2-b4a4-6dab2e81ff23
Syntax sql endsWithCaseInsensitiveUTF8(s, suffix) Arguments s โ€” String to check. String suffix โ€” Case-insensitive suffix to check for. String Returned value Returns 1 if s ends with case-insensitive suffix , otherwise 0 . UInt8 Examples Usage example sql title=Query SELECT endsWithCaseInsensitiveUTF8('ะดะฐะฝะฝั‹ั…', 'ั‹ั…'); response title=Response โ”Œโ”€endsWithCaseInsensitiveUTF8('ะดะฐะฝะฝั‹ั…', 'ั‹ั…')โ”€โ” โ”‚ 1 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ endsWithUTF8 {#endsWithUTF8} Introduced in: v23.8 Returns whether string s ends with suffix . Assumes that the string contains valid UTF-8 encoded text. If this assumption is violated, no exception is thrown and the result is undefined. Syntax sql endsWithUTF8(s, suffix) Arguments s โ€” String to check. String suffix โ€” Suffix to check for. String Returned value Returns 1 if s ends with suffix , otherwise 0 . UInt8 Examples Usage example sql title=Query SELECT endsWithUTF8('ะดะฐะฝะฝั‹ั…', 'ั‹ั…'); response title=Response โ”Œโ”€endsWithUTF8('ะดะฐะฝะฝั‹ั…', 'ั‹ั…')โ”€โ” โ”‚ 1 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ extractTextFromHTML {#extractTextFromHTML} Introduced in: v21.3 Extracts text content from HTML or XHTML. This function removes HTML tags, comments, and script/style elements, leaving only the text content. It handles: - Removal of all HTML/XML tags - Removal of comments ( <!-- --> ) - Removal of script and style elements with their content - Processing of CDATA sections (copied verbatim) - Proper whitespace handling and normalization Note: HTML entities are not decoded and should be processed with a separate function if needed. Syntax sql extractTextFromHTML(html) Arguments html โ€” String containing HTML content to extract text from. String Returned value Returns the extracted text content with normalized whitespace. String Examples Usage example ```sql title=Query SELECT extractTextFromHTML(' Page Title Hello World ! '); ``` response title=Response โ”Œโ”€extractTextFromHTML('<html><head>...')โ”€โ” โ”‚ Page Title Hello World! โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ firstLine {#firstLine} Introduced in: v23.7 Returns the first line of a multi-line string. Syntax sql firstLine(s) Arguments s โ€” Input string. String Returned value Returns the first line of the input string or the whole string if there are no line separators. String Examples Usage example sql title=Query SELECT firstLine('foo\\nbar\\nbaz') response title=Response โ”Œโ”€firstLine('foo\nbar\nbaz')โ”€โ” โ”‚ foo โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ idnaDecode {#idnaDecode} Introduced in: v24.1
{"source_file": "string-functions.md"}
[ 0.0208746325224638, -0.021481379866600037, 0.054459527134895325, 0.0004069512942805886, -0.0741347149014473, 0.011056129820644855, 0.084082692861557, 0.03514517471194267, -0.03521663323044777, -0.038534391671419144, 0.056285008788108826, -0.027740683406591415, 0.07233448326587677, 0.006307...
8aee9923-5b7b-4e7c-9f76-4e0e0c4a3cc4
response title=Response โ”Œโ”€firstLine('foo\nbar\nbaz')โ”€โ” โ”‚ foo โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ idnaDecode {#idnaDecode} Introduced in: v24.1 Returns the Unicode (UTF-8) representation (ToUnicode algorithm) of a domain name according to the Internationalized Domain Names in Applications (IDNA) mechanism. In case of an error (e.g. because the input is invalid), the input string is returned. Note that repeated application of idnaEncode() and idnaDecode() does not necessarily return the original string due to case normalization. Syntax sql idnaDecode(s) Arguments s โ€” Input string. String Returned value Returns a Unicode (UTF-8) representation of the input string according to the IDNA mechanism of the input value. String Examples Usage example sql title=Query SELECT idnaDecode('xn--strae-oqa.xn--mnchen-3ya.de') response title=Response โ”Œโ”€idnaDecode('xn--strae-oqa.xn--mnchen-3ya.de')โ”€โ” โ”‚ straรŸe.mรผnchen.de โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ idnaEncode {#idnaEncode} Introduced in: v24.1 Returns the ASCII representation (ToASCII algorithm) of a domain name according to the Internationalized Domain Names in Applications (IDNA) mechanism. The input string must be UTF-encoded and translatable to an ASCII string, otherwise an exception is thrown. :::note No percent decoding or trimming of tabs, spaces or control characters is performed. ::: Syntax sql idnaEncode(s) Arguments s โ€” Input string. String Returned value Returns an ASCII representation of the input string according to the IDNA mechanism of the input value. String Examples Usage example sql title=Query SELECT idnaEncode('straรŸe.mรผnchen.de') response title=Response โ”Œโ”€idnaEncode('straรŸe.mรผnchen.de')โ”€โ”€โ”€โ”€โ”€โ” โ”‚ xn--strae-oqa.xn--mnchen-3ya.de โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ initcap {#initcap} Introduced in: v23.7 Converts the first letter of each word to upper case and the rest to lower case. Words are sequences of alphanumeric characters separated by non-alphanumeric characters. :::note Because initcap converts only the first letter of each word to upper case you may observe unexpected behaviour for words containing apostrophes or capital letters. This is a known behaviour and there are no plans to fix it currently. ::: Syntax sql initcap(s) Arguments s โ€” Input string. String Returned value Returns s with the first letter of each word converted to upper case. String Examples Usage example sql title=Query SELECT initcap('building for fast') response title=Response โ”Œโ”€initcap('building for fast')โ”€โ” โ”‚ Building For Fast โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Example of known behavior for words containing apostrophes or capital letters sql title=Query SELECT initcap('John''s cat won''t eat.'); response title=Response โ”Œโ”€initcap('Johโ‹ฏn\'t eat.')โ”€โ” โ”‚ John'S Cat Won'T Eat. โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
{"source_file": "string-functions.md"}
[ -0.03980196639895439, -0.024319717660546303, 0.008665421977639198, -0.0390094593167305, -0.09302382916212082, -0.05174199491739273, 0.05230611562728882, -0.009782508946955204, 0.040393903851509094, -0.05211494117975235, 0.0020495119970291853, -0.048763129860162735, 0.09835020452737808, -0....
a1e6cbfd-d78c-4ab2-b420-5b2136a12fa8
sql title=Query SELECT initcap('John''s cat won''t eat.'); response title=Response โ”Œโ”€initcap('Johโ‹ฏn\'t eat.')โ”€โ” โ”‚ John'S Cat Won'T Eat. โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ initcapUTF8 {#initcapUTF8} Introduced in: v23.7 Like initcap , initcapUTF8 converts the first letter of each word to upper case and the rest to lower case. Assumes that the string contains valid UTF-8 encoded text. If this assumption is violated, no exception is thrown and the result is undefined. :::note This function does not detect the language, e.g. for Turkish the result might not be exactly correct (i/ฤฐ vs. i/I). If the length of the UTF-8 byte sequence is different for upper and lower case of a code point, the result may be incorrect for this code point. ::: Syntax sql initcapUTF8(s) Arguments s โ€” Input string. String Returned value Returns s with the first letter of each word converted to upper case. String Examples Usage example sql title=Query SELECT initcapUTF8('ะฝะต ั‚ะพั€ะผะพะทะธั‚') response title=Response โ”Œโ”€initcapUTF8('ะฝะต ั‚ะพั€ะผะพะทะธั‚')โ”€โ” โ”‚ ะะต ะขะพั€ะผะพะทะธั‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ isValidASCII {#isValidASCII} Introduced in: v25.9 Returns 1 if the input String or FixedString contains only ASCII bytes (0x00โ€“0x7F), otherwise 0. Syntax ```sql ``` Aliases : isASCII Arguments None. Returned value Examples isValidASCII sql title=Query SELECT isValidASCII('hello') AS is_ascii, isValidASCII('ไฝ ๅฅฝ') AS is_not_ascii ```response title=Response ``` isValidUTF8 {#isValidUTF8} Introduced in: v20.1 Checks if the set of bytes constitutes valid UTF-8-encoded text. Syntax sql isValidUTF8(s) Arguments s โ€” The string to check for UTF-8 encoded validity. String Returned value Returns 1 , if the set of bytes constitutes valid UTF-8-encoded text, otherwise 0 . UInt8 Examples Usage example sql title=Query SELECT isValidUTF8('\\xc3\\xb1') AS valid, isValidUTF8('\\xc3\\x28') AS invalid response title=Response โ”Œโ”€validโ”€โ”ฌโ”€invalidโ”€โ” โ”‚ 1 โ”‚ 0 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ jaroSimilarity {#jaroSimilarity} Introduced in: v24.1 Calculates the Jaro similarity between two byte strings. Syntax sql jaroSimilarity(s1, s2) Arguments s1 โ€” First input string. String s2 โ€” Second input string. String Returned value Returns the Jaro similarity between the two strings. Float64 Examples Usage example sql title=Query SELECT jaroSimilarity('clickhouse', 'click') response title=Response โ”Œโ”€jaroSimilarity('clickhouse', 'click')โ”€โ” โ”‚ 0.8333333333333333 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ jaroWinklerSimilarity {#jaroWinklerSimilarity} Introduced in: v24.1 Calculates the Jaro-Winkler similarity between two byte strings. Syntax sql jaroWinklerSimilarity(s1, s2) Arguments s1 โ€” First input string. String s2 โ€” Second input string. String Returned value
{"source_file": "string-functions.md"}
[ 0.001888464204967022, -0.0012220435310155153, 0.06681250035762787, 0.02014130726456642, -0.09641733020544052, -0.029395293444395065, 0.1148785948753357, 0.02541070245206356, 0.002306201960891485, -0.037998396903276443, 0.05703970417380333, -0.05476713925600052, 0.11248768121004105, -0.0313...
bb613474-fdfc-4d71-a63a-54c50602fe08
Syntax sql jaroWinklerSimilarity(s1, s2) Arguments s1 โ€” First input string. String s2 โ€” Second input string. String Returned value Returns the Jaro-Winkler similarity between the two strings. Float64 Examples Usage example sql title=Query SELECT jaroWinklerSimilarity('clickhouse', 'click') response title=Response โ”Œโ”€jaroWinklerSimilarity('clickhouse', 'click')โ”€โ” โ”‚ 0.8999999999999999 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ left {#left} Introduced in: v22.1 Returns a substring of string s with a specified offset starting from the left. Syntax sql left(s, offset) Arguments s โ€” The string to calculate a substring from. String or FixedString offset โ€” The number of bytes of the offset. (U)Int* Returned value Returns: - For positive offset , a substring of s with offset many bytes, starting from the left of the string. - For negative offset , a substring of s with length(s) - |offset| bytes, starting from the left of the string. - An empty string if length is 0 . String Examples Positive offset sql title=Query SELECT left('Hello World', 5) response title=Response Helllo Negative offset sql title=Query SELECT left('Hello World', -6) response title=Response Hello leftPad {#leftPad} Introduced in: v21.8 Pads a string from the left with spaces or with a specified string (multiple times, if needed) until the resulting string reaches the specified length . Syntax sql leftPad(string, length[, pad_string]) Aliases : lpad Arguments string โ€” Input string that should be padded. String length โ€” The length of the resulting string. If the value is smaller than the input string length, then the input string is shortened to length characters. (U)Int* pad_string โ€” Optional. The string to pad the input string with. If not specified, then the input string is padded with spaces. String Returned value Returns a left-padded string of the given length. String Examples Usage example sql title=Query SELECT leftPad('abc', 7, '*'), leftPad('def', 7) response title=Response โ”Œโ”€leftPad('abc', 7, '*')โ”€โ”ฌโ”€leftPad('def', 7)โ”€โ” โ”‚ ****abc โ”‚ def โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ leftPadUTF8 {#leftPadUTF8} Introduced in: v21.8 Pads a UTF8 string from the left with spaces or a specified string (multiple times, if needed) until the resulting string reaches the given length. Unlike leftPad which measures the string length in bytes, the string length is measured in code points. Syntax sql leftPadUTF8(string, length[, pad_string]) Arguments string โ€” Input string that should be padded. String length โ€” The length of the resulting string. If the value is smaller than the input string length, then the input string is shortened to length characters. (U)Int*
{"source_file": "string-functions.md"}
[ -0.008229054510593414, -0.03775883466005325, -0.010603617876768112, -0.011683802120387554, -0.08214011043310165, 0.003849201602861285, 0.04223709553480148, 0.09323243796825409, -0.061374954879283905, -0.046392254531383514, 0.03313157334923744, 0.005411628633737564, 0.07230672240257263, -0....
c1cd468b-a492-4b7b-9b83-6d160fb93f13
length โ€” The length of the resulting string. If the value is smaller than the input string length, then the input string is shortened to length characters. (U)Int* pad_string โ€” Optional. The string to pad the input string with. If not specified, then the input string is padded with spaces. String Returned value Returns a left-padded string of the given length. String Examples Usage example sql title=Query SELECT leftPadUTF8('ะฐะฑะฒะณ', 7, '*'), leftPadUTF8('ะดะตะถะท', 7) response title=Response โ”Œโ”€leftPadUTF8('ะฐะฑะฒะณ', 7, '*')โ”€โ”ฌโ”€leftPadUTF8('ะดะตะถะท', 7)โ”€โ” โ”‚ ***ะฐะฑะฒะณ โ”‚ ะดะตะถะท โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ leftUTF8 {#leftUTF8} Introduced in: v22.1 Returns a substring of a UTF-8-encoded string s with a specified offset starting from the left. Syntax sql leftUTF8(s, offset) Arguments s โ€” The UTF-8 encoded string to calculate a substring from. String or FixedString offset โ€” The number of bytes of the offset. (U)Int* Returned value Returns: - For positive offset , a substring of s with offset many bytes, starting from the left of the string.\n" - For negative offset , a substring of s with length(s) - |offset| bytes, starting from the left of the string.\n" - An empty string if length is 0. String Examples Positive offset sql title=Query SELECT leftUTF8('ะŸั€ะธะฒะตั‚', 4) response title=Response ะŸั€ะธะฒ Negative offset sql title=Query SELECT leftUTF8('ะŸั€ะธะฒะตั‚', -4) response title=Response ะŸั€ lengthUTF8 {#lengthUTF8} Introduced in: v1.1 Returns the length of a string in Unicode code points rather than in bytes or characters. It assumes that the string contains valid UTF-8 encoded text. If this assumption is violated, no exception is thrown and the result is undefined. Syntax sql lengthUTF8(s) Aliases : CHAR_LENGTH , CHARACTER_LENGTH Arguments s โ€” String containing valid UTF-8 encoded text. String Returned value Length of the string s in Unicode code points. UInt64 Examples Usage example sql title=Query SELECT lengthUTF8('ะ—ะดั€ะฐะฒัั‚ะฒัƒะน, ะผะธั€!') response title=Response โ”Œโ”€lengthUTF8('ะ—ะดั€ะฐะฒัั‚ะฒัƒะน, ะผะธั€!')โ”€โ” โ”‚ 16 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ lower {#lower} Introduced in: v1.1 Converts an ASCII string to lowercase. Syntax sql lower(s) Aliases : lcase Arguments s โ€” A string to convert to lowercase. String Returned value Returns a lowercase string from s . String Examples Usage example sql title=Query SELECT lower('CLICKHOUSE') response title=Response โ”Œโ”€lower('CLICKHOUSE')โ”€โ” โ”‚ clickhouse โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ lowerUTF8 {#lowerUTF8} Introduced in: v1.1 Converts a string to lowercase, assuming that the string contains valid UTF-8 encoded text. If this assumption is violated, no exception is thrown and the result is undefined. Syntax sql lowerUTF8(input) Arguments
{"source_file": "string-functions.md"}
[ -0.00185038719791919, 0.014345511794090271, -0.0068520125932991505, 0.02092294581234455, -0.06600962579250336, 0.01725872978568077, 0.05339215323328972, 0.10664516687393188, -0.010252510197460651, -0.039410319179296494, 0.005322770215570927, 0.019309047609567642, 0.07625477761030197, -0.07...
eaa26a7d-7bbe-4357-8e4c-7e8e09b6d34b
Syntax sql lowerUTF8(input) Arguments input โ€” Input string to convert to lowercase. String Returned value Returns a lowercase string. String Examples first sql title=Query SELECT lowerUTF8('Mรผnchen') as Lowerutf8; response title=Response mรผnchen normalizeUTF8NFC {#normalizeUTF8NFC} Introduced in: v21.11 Normalizes a UTF-8 string according to the NFC normalization form . Syntax sql normalizeUTF8NFC(str) Arguments str โ€” UTF-8 encoded input string. String Returned value Returns the NFC normalized form of the UTF-8 string. String Examples Usage example sql title=Query SELECT 'รฉ' AS original, -- e + combining acute accent (U+0065 + U+0301) length(original), normalizeUTF8NFC('รฉ') AS nfc_normalized, -- รฉ (U+00E9) length(nfc_normalized); response title=Response โ”Œโ”€originalโ”€โ”ฌโ”€length(original)โ”€โ”ฌโ”€nfc_normalizedโ”€โ”ฌโ”€length(nfc_normalized)โ”€โ” โ”‚ รฉ โ”‚ 2 โ”‚ รฉ โ”‚ 2 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ normalizeUTF8NFD {#normalizeUTF8NFD} Introduced in: v21.11 Normalizes a UTF-8 string according to the NFD normalization form . Syntax sql normalizeUTF8NFD(str) Arguments str โ€” UTF-8 encoded input string. String Returned value Returns the NFD normalized form of the UTF-8 string. String Examples Usage example sql title=Query SELECT 'รฉ' AS original, -- รฉ (U+00E9) length(original), normalizeUTF8NFD('รฉ') AS nfd_normalized, -- e + combining acute (U+0065 + U+0301) length(nfd_normalized); response title=Response โ”Œโ”€originalโ”€โ”ฌโ”€length(original)โ”€โ”ฌโ”€nfd_normalizedโ”€โ”ฌโ”€length(nfd_normalized)โ”€โ” โ”‚ รฉ โ”‚ 2 โ”‚ eฬ โ”‚ 3 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ normalizeUTF8NFKC {#normalizeUTF8NFKC} Introduced in: v21.11 Normalizes a UTF-8 string according to the NFKC normalization form . Syntax sql normalizeUTF8NFKC(str) Arguments str โ€” UTF-8 encoded input string. String Returned value Returns the NFKC normalized form of the UTF-8 string. String Examples Usage example sql title=Query SELECT 'โ‘  โ‘ก โ‘ข' AS original, -- Circled number characters normalizeUTF8NFKC('โ‘  โ‘ก โ‘ข') AS nfkc_normalized; -- Converts to 1 2 3 response title=Response โ”Œโ”€originalโ”€โ”ฌโ”€nfkc_normalizedโ”€โ” โ”‚ โ‘  โ‘ก โ‘ข โ”‚ 1 2 3 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ normalizeUTF8NFKD {#normalizeUTF8NFKD} Introduced in: v21.11 Normalizes a UTF-8 string according to the NFKD normalization form . Syntax sql normalizeUTF8NFKD(str) Arguments str โ€” UTF-8 encoded input string. String Returned value Returns the NFKD normalized form of the UTF-8 string. String Examples Usage example
{"source_file": "string-functions.md"}
[ 0.033244650810956955, 0.014830795116722584, 0.0025100363418459892, -0.0026905157137662172, -0.11059210449457169, 0.012230025604367256, 0.03429766744375229, 0.07801026850938797, -0.018191244453191757, -0.07329737395048141, -0.009449206292629242, -0.015884477645158768, 0.0751129686832428, -0...
d1768b59-7e33-4d52-9557-4f77a4fab506
sql normalizeUTF8NFKD(str) Arguments str โ€” UTF-8 encoded input string. String Returned value Returns the NFKD normalized form of the UTF-8 string. String Examples Usage example sql title=Query SELECT 'Hโ‚‚Oยฒ' AS original, -- H + subscript 2 + O + superscript 2 normalizeUTF8NFKD('Hโ‚‚Oยฒ') AS nfkd_normalized; -- Converts to H 2 O 2 response title=Response โ”Œโ”€originalโ”€โ”ฌโ”€nfkd_normalizedโ”€โ” โ”‚ Hโ‚‚Oยฒ โ”‚ H2O2 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ punycodeDecode {#punycodeDecode} Introduced in: v24.1 Returns the UTF8-encoded plaintext of a Punycode -encoded string. If no valid Punycode-encoded string is given, an exception is thrown. Syntax sql punycodeDecode(s) Arguments s โ€” Punycode-encoded string. String Returned value Returns the plaintext of the input value. String Examples Usage example sql title=Query SELECT punycodeDecode('Mnchen-3ya') response title=Response โ”Œโ”€punycodeDecode('Mnchen-3ya')โ”€โ” โ”‚ Mรผnchen โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ punycodeEncode {#punycodeEncode} Introduced in: v24.1 Returns the Punycode representation of a string. The string must be UTF8-encoded, otherwise the behavior is undefined. Syntax sql punycodeEncode(s) Arguments s โ€” Input value. String Returned value Returns a Punycode representation of the input value. String Examples Usage example sql title=Query SELECT punycodeEncode('Mรผnchen') response title=Response โ”Œโ”€punycodeEncode('Mรผnchen')โ”€โ” โ”‚ Mnchen-3ya โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ repeat {#repeat} Introduced in: v20.1 Concatenates a string as many times with itself as specified. Syntax sql repeat(s, n) Arguments s โ€” The string to repeat. String n โ€” The number of times to repeat the string. (U)Int* Returned value A string containing string s repeated n times. If n is negative, the function returns the empty string. String Examples Usage example sql title=Query SELECT repeat('abc', 10) response title=Response โ”Œโ”€repeat('abc', 10)โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ abcabcabcabcabcabcabcabcabcabc โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ reverseUTF8 {#reverseUTF8} Introduced in: v1.1 Reverses a sequence of Unicode code points in a string. Assumes that the string contains valid UTF-8 encoded text. If this assumption is violated, no exception is thrown and the result is undefined. Syntax sql reverseUTF8(s) Arguments s โ€” String containing valid UTF-8 encoded text. String Returned value Returns a string with the sequence of Unicode code points reversed. String Examples Usage example sql title=Query SELECT reverseUTF8('ClickHouse') response title=Response esuoHkcilC right {#right} Introduced in: v22.1 Returns a substring of string s with a specified offset starting from the right. Syntax sql right(s, offset) Arguments s โ€” The string to calculate a substring from. String or FixedString
{"source_file": "string-functions.md"}
[ 0.022363334894180298, -0.016905857250094414, -0.027934275567531586, 0.06069301441311836, -0.10014801472425461, 0.02703944407403469, 0.03435719758272171, 0.045377958565950394, -0.03586861491203308, -0.038753166794776917, 0.0006574949948117137, -0.029622254893183708, 0.00009686506382422522, ...
14e6dbd1-263a-487d-b665-08bc8970f39f
Syntax sql right(s, offset) Arguments s โ€” The string to calculate a substring from. String or FixedString offset โ€” The number of bytes of the offset. (U)Int* Returned value Returns: - For positive offset , a substring of s with offset many bytes, starting from the right of the string. - For negative offset , a substring of s with length(s) - |offset| bytes, starting from the right of the string. - An empty string if length is 0 . String Examples Positive offset sql title=Query SELECT right('Hello', 3) response title=Response llo Negative offset sql title=Query SELECT right('Hello', -3) response title=Response lo rightPad {#rightPad} Introduced in: v21.8 Pads a string from the right with spaces or with a specified string (multiple times, if needed) until the resulting string reaches the specified length . Syntax sql rightPad(string, length[, pad_string]) Aliases : rpad Arguments string โ€” Input string that should be padded. String length โ€” The length of the resulting string. If the value is smaller than the input string length, then the input string is shortened to length characters. (U)Int* pad_string โ€” Optional. The string to pad the input string with. If not specified, then the input string is padded with spaces. String Returned value Returns a right-padded string of the given length. String Examples Usage example sql title=Query SELECT rightPad('abc', 7, '*'), rightPad('abc', 7) response title=Response โ”Œโ”€rightPad('abc', 7, '*')โ”€โ”ฌโ”€rightPad('abc', 7)โ”€โ” โ”‚ abc**** โ”‚ abc โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ rightPadUTF8 {#rightPadUTF8} Introduced in: v21.8 Pads the string from the right with spaces or a specified string (multiple times, if needed) until the resulting string reaches the given length. Unlike rightPad which measures the string length in bytes, the string length is measured in code points. Syntax sql rightPadUTF8(string, length[, pad_string]) Arguments string โ€” Input string that should be padded. String length โ€” The length of the resulting string. If the value is smaller than the input string length, then the input string is shortened to length characters. (U)Int* pad_string โ€” Optional. The string to pad the input string with. If not specified, then the input string is padded with spaces. String Returned value Returns a right-padded string of the given length. String Examples Usage example sql title=Query SELECT rightPadUTF8('ะฐะฑะฒะณ', 7, '*'), rightPadUTF8('ะฐะฑะฒะณ', 7) response title=Response โ”Œโ”€rightPadUTF8('ะฐะฑะฒะณ', 7, '*')โ”€โ”ฌโ”€rightPadUTF8('ะฐะฑะฒะณ', 7)โ”€โ” โ”‚ ะฐะฑะฒะณ*** โ”‚ ะฐะฑะฒะณ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ rightUTF8 {#rightUTF8} Introduced in: v22.1 Returns a substring of UTF-8 encoded string s with a specified offset starting from the right. Syntax sql rightUTF8(s, offset)
{"source_file": "string-functions.md"}
[ -0.045582208782434464, -0.004076236858963966, -0.058316919952631, -0.02971617504954338, -0.09574458003044128, 0.006971792317926884, 0.05482105538249016, 0.11415233463048935, -0.03550887852907181, -0.020967865362763405, 0.07462378591299057, 0.022263145074248314, 0.048576753586530685, -0.101...
2474e665-f412-4561-a50f-526086f9ce86
rightUTF8 {#rightUTF8} Introduced in: v22.1 Returns a substring of UTF-8 encoded string s with a specified offset starting from the right. Syntax sql rightUTF8(s, offset) Arguments s โ€” The UTF-8 encoded string to calculate a substring from. String or FixedString offset โ€” The number of bytes of the offset. (U)Int* Returned value Returns: - For positive offset , a substring of s with offset many bytes, starting from the right of the string. - For negative offset , a substring of s with length(s) - |offset| bytes, starting from the right of the string. - An empty string if length is 0 . String Examples Positive offset sql title=Query SELECT rightUTF8('ะŸั€ะธะฒะตั‚', 4) response title=Response ะธะฒะตั‚ Negative offset sql title=Query SELECT rightUTF8('ะŸั€ะธะฒะตั‚', -4) response title=Response ะตั‚ soundex {#soundex} Introduced in: v23.4 Returns the Soundex code of a string. Syntax sql soundex(s) Arguments s โ€” Input string. String Returned value Returns the Soundex code of the input string. String Examples Usage example sql title=Query SELECT soundex('aksel') response title=Response โ”Œโ”€soundex('aksel')โ”€โ” โ”‚ A240 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ space {#space} Introduced in: v23.5 Concatenates a space ( ) as many times with itself as specified. Syntax sql space(n) Arguments n โ€” The number of times to repeat the space. (U)Int* Returned value Returns astring containing a space repeated n times. If n <= 0 , the function returns the empty string. String Examples Usage example sql title=Query SELECT space(3) AS res, length(res); response title=Response โ”Œโ”€resโ”€โ”ฌโ”€length(res)โ”€โ” โ”‚ โ”‚ 3 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ sparseGrams {#sparseGrams} Introduced in: v25.5 Finds all substrings of a given string that have a length of at least n , where the hashes of the (n-1)-grams at the borders of the substring are strictly greater than those of any (n-1)-gram inside the substring. Uses CRC32 as a hash function. Syntax sql sparseGrams(s[, min_ngram_length, max_ngram_length]) Arguments s โ€” An input string. String min_ngram_length โ€” Optional. The minimum length of extracted ngram. The default and minimal value is 3. UInt* max_ngram_length โ€” Optional. The maximum length of extracted ngram. The default value is 100. Should be not less than min_ngram_length . UInt* Returned value Returns an array of selected substrings. Array(String) Examples Usage example sql title=Query SELECT sparseGrams('alice', 3) response title=Response โ”Œโ”€sparseGrams('alice', 3)โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ ['ali','lic','lice','ice'] โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ sparseGramsHashes {#sparseGramsHashes} Introduced in: v25.5
{"source_file": "string-functions.md"}
[ -0.02017473615705967, -0.04462805390357971, -0.008415690623223782, -0.03302088379859924, -0.13013899326324463, 0.06521482020616531, 0.06418301165103912, 0.058282364159822464, -0.006274896673858166, -0.0487949401140213, 0.0401010736823082, 0.0047875321470201015, 0.034299369901418686, -0.074...
ff04484a-5864-408e-86a9-f0f3ee522284
sparseGramsHashes {#sparseGramsHashes} Introduced in: v25.5 Finds hashes of all substrings of a given string that have a length of at least n , where the hashes of the (n-1)-grams at the borders of the substring are strictly greater than those of any (n-1)-gram inside the substring. Uses CRC32 as a hash function. Syntax sql sparseGramsHashes(s[, min_ngram_length, max_ngram_length]) Arguments s โ€” An input string. String min_ngram_length โ€” Optional. The minimum length of extracted ngram. The default and minimal value is 3. UInt* max_ngram_length โ€” Optional. The maximum length of extracted ngram. The default value is 100. Should be not less than min_ngram_length . UInt* Returned value Returns an array of selected substrings CRC32 hashes. Array(UInt32) Examples Usage example sql title=Query SELECT sparseGramsHashes('alice', 3) response title=Response โ”Œโ”€sparseGramsHashes('alice', 3)โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ [1481062250,2450405249,4012725991,1918774096] โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ sparseGramsHashesUTF8 {#sparseGramsHashesUTF8} Introduced in: v25.5 Finds hashes of all substrings of a given UTF-8 string that have a length of at least n , where the hashes of the (n-1)-grams at the borders of the substring are strictly greater than those of any (n-1)-gram inside the substring. Expects UTF-8 string, throws an exception in case of invalid UTF-8 sequence. Uses CRC32 as a hash function. Syntax sql sparseGramsHashesUTF8(s[, min_ngram_length, max_ngram_length]) Arguments s โ€” An input string. String min_ngram_length โ€” Optional. The minimum length of extracted ngram. The default and minimal value is 3. UInt* max_ngram_length โ€” Optional. The maximum length of extracted ngram. The default value is 100. Should be not less than min_ngram_length . UInt* Returned value Returns an array of selected UTF-8 substrings CRC32 hashes. Array(UInt32) Examples Usage example sql title=Query SELECT sparseGramsHashesUTF8('ะฐะปะธัะฐ', 3) response title=Response โ”Œโ”€sparseGramsHashesUTF8('ะฐะปะธัะฐ', 3)โ”€โ” โ”‚ [4178533925,3855635300,561830861] โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ sparseGramsUTF8 {#sparseGramsUTF8} Introduced in: v25.5 Finds all substrings of a given UTF-8 string that have a length of at least n , where the hashes of the (n-1)-grams at the borders of the substring are strictly greater than those of any (n-1)-gram inside the substring. Expects a UTF-8 string, throws an exception in case of an invalid UTF-8 sequence. Uses CRC32 as a hash function. Syntax sql sparseGramsUTF8(s[, min_ngram_length, max_ngram_length]) Arguments s โ€” An input string. String min_ngram_length โ€” Optional. The minimum length of extracted ngram. The default and minimal value is 3. UInt* max_ngram_length โ€” Optional. The maximum length of extracted ngram. The default value is 100. Should be not less than min_ngram_length . UInt* Returned value
{"source_file": "string-functions.md"}
[ 0.008959172293543816, -0.009500265121459961, -0.03898081183433533, -0.05044747516512871, -0.013376758433878422, -0.01640958897769451, 0.047419484704732895, 0.04717390984296799, -0.04266190528869629, -0.015847662463784218, -0.009722384624183178, -0.029889941215515137, 0.06101605296134949, -...
7791b21d-4cd8-488a-b986-effe39b1b540
max_ngram_length โ€” Optional. The maximum length of extracted ngram. The default value is 100. Should be not less than min_ngram_length . UInt* Returned value Returns an array of selected UTF-8 substrings. Array(String) Examples Usage example sql title=Query SELECT sparseGramsUTF8('ะฐะปะธัะฐ', 3) response title=Response โ”Œโ”€sparseGramsUTF8('ะฐะปะธัะฐ', 3)โ”€โ” โ”‚ ['ะฐะปะธ','ะปะธั','ะธัะฐ'] โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ startsWith {#startsWith} Introduced in: v1.1 Checks whether a string begins with the provided string. Syntax sql startsWith(s, prefix) Arguments s โ€” String to check. String prefix โ€” Prefix to check for. String Returned value Returns 1 if s starts with prefix , otherwise 0 . UInt8 Examples Usage example sql title=Query SELECT startsWith('ClickHouse', 'Click'); response title=Response โ”Œโ”€startsWith('โ‹ฏ', 'Click')โ”€โ” โ”‚ 1 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ startsWithCaseInsensitive {#startsWithCaseInsensitive} Introduced in: v25.9 Checks whether a string begins with the provided case-insensitive string. Syntax sql startsWithCaseInsensitive(s, prefix) Arguments s โ€” String to check. String prefix โ€” Case-insensitive prefix to check for. String Returned value Returns 1 if s starts with case-insensitive prefix , otherwise 0 . UInt8 Examples Usage example sql title=Query SELECT startsWithCaseInsensitive('ClickHouse', 'CLICK'); response title=Response โ”Œโ”€startsWithCaseInsensitive('โ‹ฏ', 'CLICK')โ”€โ” โ”‚ 1 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ startsWithCaseInsensitiveUTF8 {#startsWithCaseInsensitiveUTF8} Introduced in: v25.9 Checks if a string starts with the provided case-insensitive prefix. Assumes that the string contains valid UTF-8 encoded text. If this assumption is violated, no exception is thrown and the result is undefined. Syntax sql startsWithCaseInsensitiveUTF8(s, prefix) Arguments s โ€” String to check. String prefix โ€” Case-insensitive prefix to check for. String Returned value Returns 1 if s starts with case-insensitive prefix , otherwise 0 . UInt8 Examples Usage example sql title=Query SELECT startsWithCaseInsensitiveUTF8('ะฟั€ะธัั‚ะฐะฒะบะฐ', 'ะฟั€ะธ') response title=Response โ”Œโ”€startsWithUTโ‹ฏะบะฐ', 'ะฟั€ะธ')โ”€โ” โ”‚ 1 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ startsWithUTF8 {#startsWithUTF8} Introduced in: v23.8 Checks if a string starts with the provided prefix. Assumes that the string contains valid UTF-8 encoded text. If this assumption is violated, no exception is thrown and the result is undefined. Syntax sql startsWithUTF8(s, prefix) Arguments s โ€” String to check. String prefix โ€” Prefix to check for. String Returned value Returns 1 if s starts with prefix , otherwise 0 . UInt8 Examples Usage example sql title=Query SELECT startsWithUTF8('ะฟั€ะธัั‚ะฐะฒะบะฐ', 'ะฟั€ะธ')
{"source_file": "string-functions.md"}
[ -0.005093120038509369, -0.05647401139140129, -0.046204593032598495, -0.0035110251046717167, -0.06287316232919693, -0.01907355710864067, 0.08186672627925873, 0.07128483802080154, -0.049610454589128494, -0.046112556010484695, 0.004055535886436701, -0.000014013199688633904, 0.00917259231209755,...
ee870de6-f222-4ece-b2ff-92bcf3152b43
Returned value Returns 1 if s starts with prefix , otherwise 0 . UInt8 Examples Usage example sql title=Query SELECT startsWithUTF8('ะฟั€ะธัั‚ะฐะฒะบะฐ', 'ะฟั€ะธ') response title=Response โ”Œโ”€startsWithUTโ‹ฏะบะฐ', 'ะฟั€ะธ')โ”€โ” โ”‚ 1 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ stringBytesEntropy {#stringBytesEntropy} Introduced in: v25.6 Calculates Shannon's entropy of byte distribution in a string. Syntax sql stringBytesEntropy(s) Arguments s โ€” The string to analyze. String Returned value Returns Shannon's entropy of byte distribution in the string. Float64 Examples Usage example sql title=Query SELECT stringBytesEntropy('Hello, world!') response title=Response โ”Œโ”€stringBytesEntropy('Hello, world!')โ”€โ” โ”‚ 3.07049960 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ stringBytesUniq {#stringBytesUniq} Introduced in: v25.6 Counts the number of distinct bytes in a string. Syntax sql stringBytesUniq(s) Arguments s โ€” The string to analyze. String Returned value Returns the number of distinct bytes in the string. UInt16 Examples Usage example sql title=Query SELECT stringBytesUniq('Hello') response title=Response โ”Œโ”€stringBytesUniq('Hello')โ”€โ” โ”‚ 4 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ stringJaccardIndex {#stringJaccardIndex} Introduced in: v23.11 Calculates the Jaccard similarity index between two byte strings. Syntax sql stringJaccardIndex(s1, s2) Arguments s1 โ€” First input string. String s2 โ€” Second input string. String Returned value Returns the Jaccard similarity index between the two strings. Float64 Examples Usage example sql title=Query SELECT stringJaccardIndex('clickhouse', 'mouse') response title=Response โ”Œโ”€stringJaccardIndex('clickhouse', 'mouse')โ”€โ” โ”‚ 0.4 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ stringJaccardIndexUTF8 {#stringJaccardIndexUTF8} Introduced in: v23.11 Like stringJaccardIndex but for UTF8-encoded strings. Syntax sql stringJaccardIndexUTF8(s1, s2) Arguments s1 โ€” First input UTF8 string. String s2 โ€” Second input UTF8 string. String Returned value Returns the Jaccard similarity index between the two UTF8 strings. Float64 Examples Usage example sql title=Query SELECT stringJaccardIndexUTF8('ๆˆ‘็ˆฑไฝ ', 'ๆˆ‘ไนŸ็ˆฑไฝ ') response title=Response โ”Œโ”€stringJaccardIndexUTF8('ๆˆ‘็ˆฑไฝ ', 'ๆˆ‘ไนŸ็ˆฑไฝ ')โ”€โ” โ”‚ 0.75 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ substring {#substring} Introduced in: v1.1 Returns the substring of a string s which starts at the specified byte index offset . Byte counting starts from 1 with the following logic: - If offset is 0 , an empty string is returned. - If offset is negative, the substring starts pos characters from the end of the string, rather than from the beginning.
{"source_file": "string-functions.md"}
[ 0.010364189743995667, -0.032718442380428314, -0.057075925171375275, 0.03560928255319595, -0.07815594226121902, -0.017275309190154076, 0.11495735496282578, -0.00237276847474277, 0.03458278253674507, 0.021017951890826225, -0.029776547104120255, -0.04041670262813568, 0.07558809220790863, -0.0...
71e5562a-f80f-4134-a71f-997e782e8be7
An optional argument length specifies the maximum number of bytes the returned substring may have. Syntax sql substring(s, offset[, length]) Aliases : byteSlice , mid , substr Arguments s โ€” The string to calculate a substring from. String or FixedString or Enum offset โ€” The starting position of the substring in s . (U)Int* length โ€” Optional. The maximum length of the substring. (U)Int* Returned value Returns a substring of s with length many bytes, starting at index offset . String Examples Basic usage sql title=Query SELECT 'database' AS db, substr(db, 5), substr(db, 5, 1) response title=Response โ”Œโ”€dbโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€substring('database', 5)โ”€โ”ฌโ”€substring('database', 5, 1)โ”€โ” โ”‚ database โ”‚ base โ”‚ b โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ substringIndex {#substringIndex} Introduced in: v23.7 Returns the substring of s before count occurrences of the delimiter delim , as in Spark or MySQL. Syntax sql substringIndex(s, delim, count) Aliases : SUBSTRING_INDEX Arguments s โ€” The string to extract substring from. String delim โ€” The character to split. String count โ€” The number of occurrences of the delimiter to count before extracting the substring. If count is positive, everything to the left of the final delimiter (counting from the left) is returned. If count is negative, everything to the right of the final delimiter (counting from the right) is returned. UInt or Int Returned value Returns a substring of s before count occurrences of delim . String Examples Usage example sql title=Query SELECT substringIndex('www.clickhouse.com', '.', 2) response title=Response โ”Œโ”€substringIndex('www.clickhouse.com', '.', 2)โ”€โ” โ”‚ www.clickhouse โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ substringIndexUTF8 {#substringIndexUTF8} Introduced in: v23.7 Returns the substring of s before count occurrences of the delimiter delim , specifically for Unicode code points. Assumes that the string contains valid UTF-8 encoded text. If this assumption is violated, no exception is thrown and the result is undefined. Syntax sql substringIndexUTF8(s, delim, count) Arguments s โ€” The string to extract substring from. String delim โ€” The character to split. String count โ€” The number of occurrences of the delimiter to count before extracting the substring. If count is positive, everything to the left of the final delimiter (counting from the left) is returned. If count is negative, everything to the right of the final delimiter (counting from the right) is returned. UInt or Int Returned value Returns a substring of s before count occurrences of delim . String Examples UTF8 example sql title=Query SELECT substringIndexUTF8('www.straรŸen-in-europa.de', '.', 2) response title=Response www.straรŸen-in-europa
{"source_file": "string-functions.md"}
[ -0.018833568319678307, -0.0211500097066164, -0.0014127959730103612, -0.002582718851044774, -0.02819780632853508, -0.0212387815117836, 0.04696585610508919, 0.1111159697175026, 0.0038060387596488, -0.05098314955830574, -0.0731901079416275, 0.04184595122933388, 0.03578171879053116, -0.0886002...
fa7835d7-4d56-4100-ac05-7e028815a9c5
Examples UTF8 example sql title=Query SELECT substringIndexUTF8('www.straรŸen-in-europa.de', '.', 2) response title=Response www.straรŸen-in-europa substringUTF8 {#substringUTF8} Introduced in: v1.1 Returns the substring of a string s which starts at the specified byte index offset for Unicode code points. Byte counting starts from 1 with the following logic: - If offset is 0 , an empty string is returned. - If offset is negative, the substring starts pos characters from the end of the string, rather than from the beginning. An optional argument length specifies the maximum number of bytes the returned substring may have. :::note This function assumes that the string contains valid UTF-8 encoded text. If this assumption is violated, no exception is thrown and the result is undefined. ::: Syntax sql substringUTF8(s, offset[, length]) Arguments s โ€” The string to calculate a substring from. String or FixedString or Enum offset โ€” The starting position of the substring in s . Int or UInt length โ€” The maximum length of the substring. Optional. Int or UInt Returned value Returns a substring of s with length many bytes, starting at index offset . String Examples Usage example sql title=Query SELECT 'Tรคglich grรผรŸt das Murmeltier.' AS str, substringUTF8(str, 9), substringUTF8(str, 9, 5) response title=Response Tรคglich grรผรŸt das Murmeltier. grรผรŸt das Murmeltier. grรผรŸt toValidUTF8 {#toValidUTF8} Introduced in: v20.1 Converts a string to valid UTF-8 encoding by replacing any invalid UTF-8 characters with the replacement character ๏ฟฝ (U+FFFD). When multiple consecutive invalid characters are found, they are collapsed into a single replacement character. Syntax sql toValidUTF8(s) Arguments s โ€” Any set of bytes represented as the String data type object. String Returned value Returns a valid UTF-8 string. String Examples Usage example sql title=Query SELECT toValidUTF8('\\x61\\xF0\\x80\\x80\\x80b') response title=Response c โ”Œโ”€toValidUTF8('a๏ฟฝ๏ฟฝ๏ฟฝ๏ฟฝb')โ”€โ” โ”‚ a๏ฟฝb โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ trimBoth {#trimBoth} Introduced in: v20.1 Removes the specified characters from the start and end of a string. By default, removes common whitespace (ASCII) characters. Syntax sql trimBoth(s[, trim_characters]) Aliases : trim Arguments s โ€” String to trim. String trim_characters โ€” Optional. Characters to trim. If not specified, common whitespace characters are removed. String Returned value Returns the string with specified characters trimmed from both ends. String Examples Usage example sql title=Query SELECT trimBoth('$$ClickHouse$$', '$') response title=Response โ”Œโ”€trimBoth('$$โ‹ฏse$$', '$')โ”€โ” โ”‚ ClickHouse โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ trimLeft {#trimLeft} Introduced in: v20.1
{"source_file": "string-functions.md"}
[ -0.010852803476154804, 0.004392086993902922, 0.013460232876241207, -0.008072982542216778, -0.09524527937173843, 0.0026112240739166737, 0.05386306717991829, 0.11880868673324585, 0.016263708472251892, -0.063606396317482, -0.012938403524458408, -0.03336622193455696, 0.07355616241693497, -0.03...
9be5d823-66bf-4955-b9af-6d0b80fe653c
response title=Response โ”Œโ”€trimBoth('$$โ‹ฏse$$', '$')โ”€โ” โ”‚ ClickHouse โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ trimLeft {#trimLeft} Introduced in: v20.1 Removes the specified characters from the start of a string. By default, removes common whitespace (ASCII) characters. Syntax sql trimLeft(input[, trim_characters]) Aliases : ltrim Arguments input โ€” String to trim. String trim_characters โ€” Optional. Characters to trim. If not specified, common whitespace characters are removed. String Returned value Returns the string with specified characters trimmed from the left. String Examples Usage example sql title=Query SELECT trimLeft('ClickHouse', 'Click'); response title=Response โ”Œโ”€trimLeft('Clโ‹ฏ', 'Click')โ”€โ” โ”‚ House โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ trimRight {#trimRight} Introduced in: v20.1 Removes the specified characters from the end of a string. By default, removes common whitespace (ASCII) characters. Syntax sql trimRight(s[, trim_characters]) Aliases : rtrim Arguments s โ€” String to trim. String trim_characters โ€” Optional characters to trim. If not specified, common whitespace characters are removed. String Returned value Returns the string with specified characters trimmed from the right. String Examples Usage example sql title=Query SELECT trimRight('ClickHouse','House'); response title=Response โ”Œโ”€trimRight('Cโ‹ฏ', 'House')โ”€โ” โ”‚ Click โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ tryBase32Decode {#tryBase32Decode} Introduced in: v25.6 Accepts a string and decodes it using Base32 encoding scheme. Syntax sql tryBase32Decode(encoded) Arguments encoded โ€” String column or constant to decode. If the string is not valid Base32-encoded, returns an empty string in case of error. String Returned value Returns a string containing the decoded value of the argument. String Examples Usage example sql title=Query SELECT tryBase32Decode('IVXGG33EMVSA===='); response title=Response โ”Œโ”€tryBase32Decode('IVXGG33EMVSA====')โ”€โ” โ”‚ Encoded โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ tryBase58Decode {#tryBase58Decode} Introduced in: v22.10 Like base58Decode , but returns an empty string in case of error. Syntax sql tryBase58Decode(encoded) Arguments encoded โ€” String column or constant. If the string is not valid Base58-encoded, returns an empty string in case of error. String Returned value Returns a string containing the decoded value of the argument. String Examples Usage example sql title=Query SELECT tryBase58Decode('3dc8KtHrwM') AS res, tryBase58Decode('invalid') AS res_invalid; response title=Response โ”Œโ”€resโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€res_invalidโ”€โ” โ”‚ Encoded โ”‚ โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ tryBase64Decode {#tryBase64Decode} Introduced in: v18.16 Like base64Decode , but returns an empty string in case of error. Syntax sql tryBase64Decode(encoded) Arguments
{"source_file": "string-functions.md"}
[ 0.01753087155520916, 0.017420759424567223, 0.07999852299690247, 0.06866545230150223, -0.11310754716396332, -0.0268965195864439, 0.09038292616605759, -0.0007493303855881095, 0.0034706387668848038, -0.01637384667992592, 0.09066159278154373, 0.00961625762283802, 0.06987284123897552, -0.062426...
8fada8a6-e57a-4289-a694-542a5395aabe
tryBase64Decode {#tryBase64Decode} Introduced in: v18.16 Like base64Decode , but returns an empty string in case of error. Syntax sql tryBase64Decode(encoded) Arguments encoded โ€” String column or constant to decode. If the string is not valid Base64-encoded, returns an empty string in case of error. String Returned value Returns a string containing the decoded value of the argument. String Examples Usage example sql title=Query SELECT tryBase64Decode('Y2xpY2tob3VzZQ==') response title=Response โ”Œโ”€tryBase64Decode('Y2xpY2tob3VzZQ==')โ”€โ” โ”‚ clickhouse โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ tryBase64URLDecode {#tryBase64URLDecode} Introduced in: v18.16 Like base64URLDecode , but returns an empty string in case of error. Syntax sql tryBase64URLDecode(encoded) Arguments encoded โ€” String column or constant to decode. If the string is not valid Base64-encoded, returns an empty string in case of error. String Returned value Returns a string containing the decoded value of the argument. String Examples Usage example sql title=Query SELECT tryBase64URLDecode('aHR0cHM6Ly9jbGlja2hvdXNlLmNvbQ') response title=Response โ”Œโ”€tryBase64URLDecode('aHR0cHM6Ly9jbGlja2hvdXNlLmNvbQ')โ”€โ” โ”‚ https://clickhouse.com โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ tryIdnaEncode {#tryIdnaEncode} Introduced in: v24.1 Returns the Unicode (UTF-8) representation (ToUnicode algorithm) of a domain name according to the Internationalized Domain Names in Applications (IDNA) mechanism. In case of an error it returns an empty string instead of throwing an exception. Syntax sql tryIdnaEncode(s) Arguments s โ€” Input string. String Returned value Returns an ASCII representation of the input string according to the IDNA mechanism of the input value, or empty string if input is invalid. String Examples Usage example sql title=Query SELECT tryIdnaEncode('straรŸe.mรผnchen.de') response title=Response โ”Œโ”€tryIdnaEncode('straรŸe.mรผnchen.de')โ”€โ”€โ” โ”‚ xn--strae-oqa.xn--mnchen-3ya.de โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ tryPunycodeDecode {#tryPunycodeDecode} Introduced in: v24.1 Like punycodeDecode but returns an empty string if no valid Punycode-encoded string is given. Syntax sql tryPunycodeDecode(s) Arguments s โ€” Punycode-encoded string. String Returned value Returns the plaintext of the input value, or empty string if input is invalid. String Examples Usage example sql title=Query SELECT tryPunycodeDecode('Mnchen-3ya') response title=Response โ”Œโ”€tryPunycodeDecode('Mnchen-3ya')โ”€โ” โ”‚ Mรผnchen โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ upper {#upper} Introduced in: v1.1 Converts the ASCII Latin symbols in a string to uppercase. Syntax sql upper(s) Aliases : ucase Arguments s โ€” The string to convert to uppercase. String Returned value
{"source_file": "string-functions.md"}
[ 0.033943451941013336, -0.020260678604245186, -0.0264522023499012, 0.04013602435588837, -0.06495731323957443, -0.01954037696123123, 0.009118846617639065, -0.0016415041172876954, -0.01733480580151081, -0.01986510679125786, 0.03130904585123062, -0.06636248528957367, 0.0719982460141182, -0.029...
31fd8d67-fd79-40d8-9017-4b667e927ff0
Converts the ASCII Latin symbols in a string to uppercase. Syntax sql upper(s) Aliases : ucase Arguments s โ€” The string to convert to uppercase. String Returned value Returns an uppercase string from s . String Examples Usage example sql title=Query SELECT upper('clickhouse') response title=Response โ”Œโ”€upper('clickhouse')โ”€โ” โ”‚ CLICKHOUSE โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ upperUTF8 {#upperUTF8} Introduced in: v1.1 Converts a string to uppercase, assuming that the string contains valid UTF-8 encoded text. If this assumption is violated, no exception is thrown and the result is undefined. :::note This function doesn't detect the language, e.g. for Turkish the result might not be exactly correct (i/ฤฐ vs. i/I). If the length of the UTF-8 byte sequence is different for upper and lower case of a code point (such as แบž and รŸ ), the result may be incorrect for that code point. ::: Syntax sql upperUTF8(s) Arguments s โ€” A string type. String Returned value A String data type value. String Examples Usage example sql title=Query SELECT upperUTF8('Mรผnchen') AS Upperutf8 response title=Response โ”Œโ”€Upperutf8โ”€โ” โ”‚ MรœNCHEN โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
{"source_file": "string-functions.md"}
[ -0.013451623730361462, -0.047795847058296204, 0.04791427031159401, 0.007947618141770363, -0.10609415173530579, -0.049661632627248764, 0.07901446521282196, 0.06871623545885086, -0.01488299760967493, -0.0566800981760025, 0.024190425872802734, -0.020534804090857506, 0.06365228444337845, -0.03...
74a476b4-acc4-42d0-b386-91edd9cdc4af
description: 'Landing page for Regular Functions' slug: /sql-reference/functions/regular-functions title: 'Regular functions' doc_type: 'landing-page'
{"source_file": "regular-functions-index.md"}
[ 0.026610499247908592, -0.025355007499456406, -0.009625433944165707, -0.011622351594269276, -0.04573903977870941, -0.05120929330587387, -0.0048690419644117355, 0.03387890011072159, -0.08537156134843826, -0.012330184690654278, -0.017059145495295525, 0.015098980627954006, 0.019351527094841003, ...
bdefa103-afe9-4027-8e71-bfff38825c20
| Page | Description | |--------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------| | Overview | Overview of all functions. | | Machine Learning | Functions for machine learning. | | Introspection | Functions for introspection of ClickHouse. | | arrayJoin | The arrayJoin function which takes each row and generates a set of rows (unfold) | | Searching in Strings | Functions for searching within strings. | | Hash | Hashing functions. | | UUIDs | Functions for Working with UUIDs. | | Time-Series | Functions for working with time series | | Random Numbers | Functions for random number generation. | | NLP | Functions for Natural Language Processing. | | Conditional | Conditional functions. | | Nullable | Functions for working with NULL. | | Bit | Bitwise functions. | | Time Window | Functions which return the inclusive lower and exclusive upper bound of the corresponding window. | | IP Address | Functions for Working with IPv4 and IPv6 Addresses. | | Splitting Strings | Functions for splitting strings. | | Tuples | Functions for working with tuples. | | String replacement
{"source_file": "regular-functions-index.md"}
[ -0.03776535764336586, 0.007811244111508131, -0.008746998384594917, -0.005856119096279144, -0.034302882850170135, 0.03278353437781334, 0.07533968240022659, -0.08125396817922592, -0.03930547833442688, 0.03320636972784996, -0.015387850813567638, 0.019681433215737343, 0.018273325636982918, -0....
ccf54be3-21fd-4ea8-84d2-f8e4bda7a6b9
| Tuples | Functions for working with tuples. | | String replacement | Functions for string replacement. | | User Defined Functions | User Defined Functions. | | Comparison | Comparison functions (equals, less, greater etc.) | | Other | Functions which don't fit into any other category. | | JSON | Functions for working with JSON. | | URL | Functions for working with URLs. | | Encoding | Functions for encoding data. | | ULID | Functions for Working with ULID. | | Maps | Functions for working with Maps. | | Dictionaries | Functions for working with dictionaries. | | IN | IN operators | | Files | The file function. | | Arrays | Functions for working with arrays. | | String | Functions for working with Strings. (Functions for searching in strings and for replacing in strings are described separately.) | | DateTime | Functions for working with dates and times. | | Logical | Functions which perform logical operations on arguments of arbitrary numeric types. | | Rounding | Functions for rounding. | | uniqTheta | uniqTheta functions work on two uniqThetaSketch objects to do set operation calculations such as โˆช / โˆฉ / ร—. | | Distance | Functions for calculating vector norms, distances, normalization, and common operations in linear algebra and machine learning. | | Bitmap
{"source_file": "regular-functions-index.md"}
[ -0.058638084679841995, -0.03746117651462555, -0.0253500547260046, -0.015084800310432911, -0.02491561509668827, -0.06851882487535477, -0.006327095441520214, 0.028922714293003082, -0.06868783384561539, -0.023197200149297714, -0.0166825782507658, 0.0037151528522372246, -0.00761303910985589, -...
b1579c2c-fa44-4951-9d38-f4ea0d5ca9df
| Distance | Functions for calculating vector norms, distances, normalization, and common operations in linear algebra and machine learning. | | Bitmap | Functions for bitmaps. | | Math | Mathematical functions. | | Financial | Financial functions. | | Encryption | Functions for encryption. | | Arithmetic | Functions for performing arithmetic on UInt , Int or Float types. | | Embedded Dictionaries | Functions for Working with Embedded Dictionaries | | Type Conversion | Functions for converting from one type to another type. |
{"source_file": "regular-functions-index.md"}
[ -0.004071983974426985, 0.0060438127256929874, -0.0754312202334404, -0.10223130881786346, 0.00622026901692152, -0.042548879981040955, -0.009112750180065632, -0.008415281772613525, -0.03949238732457161, -0.034308064728975296, 0.04292711615562439, 0.009138805791735649, 0.010031802579760551, 0...
6d348e6b-0b84-4a53-bfa0-2cc05c178f3f
description: 'Documentation for Functions for Working with Dates and Times' sidebar_label: 'Dates and time' slug: /sql-reference/functions/date-time-functions title: 'Functions for Working with Dates and Times' doc_type: 'reference' Functions for working with dates and times Most functions in this section accept an optional time zone argument, e.g. Europe/Amsterdam . In this case, the time zone is the specified one instead of the local (default) one. Example sql SELECT toDateTime('2016-06-15 23:00:00') AS time, toDate(time) AS date_local, toDate(time, 'Asia/Yekaterinburg') AS date_yekat, toString(time, 'US/Samoa') AS time_samoa text โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€timeโ”€โ”ฌโ”€date_localโ”€โ”ฌโ”€date_yekatโ”€โ”ฌโ”€time_samoaโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ 2016-06-15 23:00:00 โ”‚ 2016-06-15 โ”‚ 2016-06-16 โ”‚ 2016-06-15 09:00:00 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ UTCTimestamp {#UTCTimestamp} Introduced in: v22.11 Returns the current date and time at the moment of query analysis. The function is a constant expression. This function gives the same result that now('UTC') would. It was added only for MySQL support. now is the preferred usage. Syntax sql UTCTimestamp() Aliases : UTC_timestamp Arguments None. Returned value Returns the current date and time at the moment of query analysis. DateTime Examples Get current UTC timestamp sql title=Query SELECT UTCTimestamp() response title=Response โ”Œโ”€โ”€โ”€โ”€โ”€โ”€UTCTimestamp()โ”€โ” โ”‚ 2024-05-28 08:32:09 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ YYYYMMDDToDate {#YYYYMMDDToDate} Introduced in: v23.9 Converts a number containing the year, month and day number to a Date . This function is the opposite of function toYYYYMMDD() . The output is undefined if the input does not encode a valid Date value. Syntax sql YYYYMMDDToDate(YYYYMMDD) Arguments YYYYMMDD โ€” Number containing the year, month and day. (U)Int* or Float* or Decimal Returned value Returns a Date value from the provided arguments Date Examples Example sql title=Query SELECT YYYYMMDDToDate(20230911); response title=Response โ”Œโ”€toYYYYMMDD(20230911)โ”€โ” โ”‚ 2023-09-11 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ YYYYMMDDToDate32 {#YYYYMMDDToDate32} Introduced in: v23.9 Converts a number containing the year, month and day number to a Date32 . This function is the opposite of function toYYYYMMDD() . The output is undefined if the input does not encode a valid Date32 value. Syntax sql YYYYMMDDToDate32(YYYYMMDD) Arguments YYYYMMDD โ€” Number containing the year, month and day. (U)Int* or Float* or Decimal Returned value Returns a Date32 value from the provided arguments Date32 Examples Example sql title=Query SELECT YYYYMMDDToDate32(20000507); response title=Response โ”Œโ”€YYYYMMDDToDate32(20000507)โ”€โ” โ”‚ 2000-05-07 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ YYYYMMDDhhmmssToDateTime {#YYYYMMDDhhmmssToDateTime} Introduced in: v23.9
{"source_file": "date-time-functions.md"}
[ 0.01434731762856245, 0.017459716647863388, -0.0017877474892884493, 0.03671831265091896, 0.027674881741404533, -0.04664033651351929, 0.011477828025817871, 0.021552519872784615, -0.029239267110824585, 0.018044255673885345, -0.028710009530186653, -0.12004879117012024, -0.07730040699243546, 0....
aa8f39ce-6568-4b99-bd1a-b2a2bfdbe98b
response title=Response โ”Œโ”€YYYYMMDDToDate32(20000507)โ”€โ” โ”‚ 2000-05-07 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ YYYYMMDDhhmmssToDateTime {#YYYYMMDDhhmmssToDateTime} Introduced in: v23.9 Converts a number containing the year, month, day, hour, minute, and second to a DateTime . This function is the opposite of function toYYYYMMDDhhmmss() . The output is undefined if the input does not encode a valid DateTime value. Syntax sql YYYYMMDDhhmmssToDateTime(YYYYMMDDhhmmss[, timezone]) Arguments YYYYMMDDhhmmss โ€” Number containing the year, month, day, hour, minute, and second. (U)Int* or Float* or Decimal timezone โ€” Timezone name. String Returned value Returns a DateTime value from the provided arguments DateTime Examples Example sql title=Query SELECT YYYYMMDDToDateTime(20230911131415); response title=Response โ”Œโ”€โ”€โ”€โ”€โ”€โ”€YYYYMMDDhhmmssToDateTime(20230911131415)โ”€โ” โ”‚ 2023-09-11 13:14:15 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ YYYYMMDDhhmmssToDateTime64 {#YYYYMMDDhhmmssToDateTime64} Introduced in: v23.9 Converts a number containing the year, month, day, hour, minute, and second to a DateTime64 . This function is the opposite of function toYYYYMMDDhhmmss() . The output is undefined if the input does not encode a valid DateTime64 value. Syntax sql YYYYMMDDhhmmssToDateTime64(YYYYMMDDhhmmss[, precision[, timezone]]) Arguments YYYYMMDDhhmmss โ€” Number containing the year, month, day, hour, minute, and second. (U)Int* or Float* or Decimal precision โ€” Precision for the fractional part (0-9). UInt8 timezone โ€” Timezone name. String Returned value Returns a DateTime64 value from the provided arguments DateTime64 Examples Example sql title=Query SELECT YYYYMMDDhhmmssToDateTime64(20230911131415, 3, 'Asia/Istanbul'); response title=Response โ”Œโ”€YYYYMMDDhhmmโ‹ฏ/Istanbul')โ”€โ” โ”‚ 2023-09-11 13:14:15.000 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ addDate {#addDate} Introduced in: v23.9 Adds the time interval to the provided date, date with time or string-encoded date or date with time. If the addition results in a value outside the bounds of the data type, the result is undefined. Syntax sql addDate(datetime, interval) Arguments datetime โ€” The date or date with time to which interval is added. Date or Date32 or DateTime or DateTime64 or String interval โ€” Interval to add. Interval Returned value Returns date or date with time obtained by adding interval to datetime . Date or Date32 or DateTime or DateTime64 Examples Add interval to date sql title=Query SELECT addDate(toDate('2018-01-01'), INTERVAL 3 YEAR) response title=Response โ”Œโ”€addDate(toDaโ‹ฏvalYear(3))โ”€โ” โ”‚ 2021-01-01 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ addDays {#addDays} Introduced in: v1.1 Adds a specified number of days to a date, a date with time or a string-encoded date or date with time. Syntax sql addDays(datetime, num)
{"source_file": "date-time-functions.md"}
[ 0.013875346630811691, 0.0056164986453950405, -0.022518964484333992, 0.014176402240991592, -0.025185249745845795, -0.026501810178160667, 0.013548780232667923, 0.04055462405085564, -0.013725432567298412, -0.05087846890091896, -0.010698771104216576, -0.11245135962963104, -0.003369123674929142, ...
9e7d0a06-8186-4661-a0c3-ba03ff0e5aff
addDays {#addDays} Introduced in: v1.1 Adds a specified number of days to a date, a date with time or a string-encoded date or date with time. Syntax sql addDays(datetime, num) Arguments datetime โ€” Date or date with time to add specified number of days to. Date or Date32 or DateTime or DateTime64 or String num โ€” Number of days to add. (U)Int* or Float* Returned value Returns datetime plus num days. Date or Date32 or DateTime or DateTime64 Examples Add days to different date types sql title=Query WITH toDate('2024-01-01') AS date, toDateTime('2024-01-01 00:00:00') AS date_time, '2024-01-01 00:00:00' AS date_time_string SELECT addDays(date, 5) AS add_days_with_date, addDays(date_time, 5) AS add_days_with_date_time, addDays(date_time_string, 5) AS add_days_with_date_time_string response title=Response โ”Œโ”€add_days_with_dateโ”€โ”ฌโ”€add_days_with_date_timeโ”€โ”ฌโ”€add_days_with_date_time_stringโ”€โ” โ”‚ 2024-01-06 โ”‚ 2024-01-06 00:00:00 โ”‚ 2024-01-06 00:00:00.000 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Using alternative INTERVAL syntax sql title=Query SELECT dateAdd('1998-06-16'::Date, INTERVAL 10 day) response title=Response โ”Œโ”€plus(CAST('1โ‹ฏvalDay(10))โ”€โ” โ”‚ 1998-06-26 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ addHours {#addHours} Introduced in: v1.1 Adds a specified number of hours to a date, a date with time or a string-encoded date or date with time. Syntax sql addHours(datetime, num) Arguments datetime โ€” Date or date with time to add specified number of hours to. Date or Date32 or DateTime or DateTime64 or String num โ€” Number of hours to add. (U)Int* or Float* Returned value Returns datetime plus num hours DateTime or DateTime64(3) Examples Add hours to different date types sql title=Query WITH toDate('2024-01-01') AS date, toDateTime('2024-01-01 00:00:00') AS date_time, '2024-01-01 00:00:00' AS date_time_string SELECT addHours(date, 12) AS add_hours_with_date, addHours(date_time, 12) AS add_hours_with_date_time, addHours(date_time_string, 12) AS add_hours_with_date_time_string response title=Response โ”Œโ”€add_hours_with_dateโ”€โ”ฌโ”€add_hours_with_date_timeโ”€โ”ฌโ”€add_hours_with_date_time_stringโ”€โ” โ”‚ 2024-01-01 12:00:00 โ”‚ 2024-01-01 12:00:00 โ”‚ 2024-01-01 12:00:00.000 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Using alternative INTERVAL syntax sql title=Query SELECT dateAdd('1998-06-16'::Date, INTERVAL 10 hour) response title=Response โ”Œโ”€plus(CAST('1โ‹ฏalHour(10))โ”€โ” โ”‚ 1998-06-16 10:00:00 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ addInterval {#addInterval} Introduced in: v22.11 Adds an interval to another interval or tuple of intervals.
{"source_file": "date-time-functions.md"}
[ 0.0043013193644583225, -0.018698273226618767, 0.010414916090667248, 0.11723469942808151, -0.10739191621541977, -0.01820058561861515, 0.058726564049720764, -0.010133612900972366, -0.09300799667835236, 0.024582838639616966, 0.056973401457071304, -0.1012863889336586, -0.026964228600263596, -0...
9be08926-75fb-4d3d-8214-d6fe454f226b
addInterval {#addInterval} Introduced in: v22.11 Adds an interval to another interval or tuple of intervals. :::note Intervals of the same type will be combined into a single interval. For instance if toIntervalDay(1) and toIntervalDay(2) are passed then the result will be (3) rather than (1,1) . ::: Syntax sql addInterval(interval_1, interval_2) Arguments interval_1 โ€” First interval or tuple of intervals. Interval or Tuple(Interval) interval_2 โ€” Second interval to be added. Interval Returned value Returns a tuple of intervals Tuple(Interval) Examples Add intervals sql title=Query SELECT addInterval(INTERVAL 1 DAY, INTERVAL 1 MONTH); SELECT addInterval((INTERVAL 1 DAY, INTERVAL 1 YEAR), INTERVAL 1 MONTH); SELECT addInterval(INTERVAL 2 DAY, INTERVAL 1 DAY) response title=Response โ”Œโ”€addInterval(toIntervalDay(1), toIntervalMonth(1))โ”€โ” โ”‚ (1,1) โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”Œโ”€addInterval((toIntervalDay(1), toIntervalYear(1)), toIntervalMonth(1))โ”€โ” โ”‚ (1,1,1) โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”Œโ”€addInterval(toIntervalDay(2), toIntervalDay(1))โ”€โ” โ”‚ (3) โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ addMicroseconds {#addMicroseconds} Introduced in: v22.6 Adds a specified number of microseconds to a date with time or a string-encoded date with time. Syntax sql addMicroseconds(datetime, num) Arguments datetime โ€” Date with time to add specified number of microseconds to. DateTime or DateTime64 or String num โ€” Number of microseconds to add. (U)Int* or Float* Returned value Returns date_time plus num microseconds DateTime64 Examples Add microseconds to different date time types sql title=Query WITH toDateTime('2024-01-01 00:00:00') AS date_time, '2024-01-01 00:00:00' AS date_time_string SELECT addMicroseconds(date_time, 1000000) AS add_microseconds_with_date_time, addMicroseconds(date_time_string, 1000000) AS add_microseconds_with_date_time_string response title=Response โ”Œโ”€add_microseconds_with_date_timeโ”€โ”ฌโ”€add_microseconds_with_date_time_stringโ”€โ” โ”‚ 2024-01-01 00:00:01.000000 โ”‚ 2024-01-01 00:00:01.000000 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Using alternative INTERVAL syntax sql title=Query SELECT dateAdd('1998-06-16'::DateTime, INTERVAL 10 microsecond) response title=Response โ”Œโ”€plus(CAST('19โ‹ฏosecond(10))โ”€โ” โ”‚ 1998-06-16 00:00:00.000010 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ addMilliseconds {#addMilliseconds} Introduced in: v22.6 Adds a specified number of milliseconds to a date with time or a string-encoded date with time. Syntax sql addMilliseconds(datetime, num) Arguments
{"source_file": "date-time-functions.md"}
[ -0.03186032548546791, -0.02514783665537834, 0.028303921222686768, 0.06773904711008072, -0.08059253543615341, 0.0007644444121979177, 0.0370694138109684, -0.01998252049088478, -0.005489191506057978, -0.04385355859994888, 0.06222127750515938, -0.12136147171258926, 0.0299794040620327, -0.03114...
c4f6f8f8-ae1f-4f7e-83e2-9e06ceafedbc
Introduced in: v22.6 Adds a specified number of milliseconds to a date with time or a string-encoded date with time. Syntax sql addMilliseconds(datetime, num) Arguments datetime โ€” Date with time to add specified number of milliseconds to. DateTime or DateTime64 or String num โ€” Number of milliseconds to add. (U)Int* or Float* Returned value Returns datetime plus num milliseconds DateTime64 Examples Add milliseconds to different date time types sql title=Query WITH toDateTime('2024-01-01 00:00:00') AS date_time, '2024-01-01 00:00:00' AS date_time_string SELECT addMilliseconds(date_time, 1000) AS add_milliseconds_with_date_time, addMilliseconds(date_time_string, 1000) AS add_milliseconds_with_date_time_string response title=Response โ”Œโ”€add_milliseconds_with_date_timeโ”€โ”ฌโ”€add_milliseconds_with_date_time_stringโ”€โ” โ”‚ 2024-01-01 00:00:01.000 โ”‚ 2024-01-01 00:00:01.000 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Using alternative INTERVAL syntax sql title=Query SELECT dateAdd('1998-06-16'::DateTime, INTERVAL 10 millisecond) response title=Response โ”Œโ”€plus(CAST('1โ‹ฏsecond(10))โ”€โ” โ”‚ 1998-06-16 00:00:00.010 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ addMinutes {#addMinutes} Introduced in: v1.1 Adds a specified number of minutes to a date, a date with time or a string-encoded date or date with time. Syntax sql addMinutes(datetime, num) Arguments datetime โ€” Date or date with time to add specified number of minutes to. Date or Date32 or DateTime or DateTime64 or String num โ€” Number of minutes to add. (U)Int* or Float* Returned value Returns datetime plus num minutes DateTime or DateTime64(3) Examples Add minutes to different date types sql title=Query WITH toDate('2024-01-01') AS date, toDateTime('2024-01-01 00:00:00') AS date_time, '2024-01-01 00:00:00' AS date_time_string SELECT addMinutes(date, 20) AS add_minutes_with_date, addMinutes(date_time, 20) AS add_minutes_with_date_time, addMinutes(date_time_string, 20) AS add_minutes_with_date_time_string response title=Response โ”Œโ”€add_minutes_with_dateโ”€โ”ฌโ”€add_minutes_with_date_timeโ”€โ”ฌโ”€add_minutes_with_date_time_stringโ”€โ” โ”‚ 2024-01-01 00:20:00 โ”‚ 2024-01-01 00:20:00 โ”‚ 2024-01-01 00:20:00.000 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Using alternative INTERVAL syntax sql title=Query SELECT dateAdd('1998-06-16'::Date, INTERVAL 10 minute) response title=Response โ”Œโ”€plus(CAST('1โ‹ฏMinute(10))โ”€โ” โ”‚ 1998-06-16 00:10:00 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ addMonths {#addMonths} Introduced in: v1.1 Adds a specified number of months to a date, a date with time or a string-encoded date or date with time. Syntax sql addMonths(datetime, num) Arguments
{"source_file": "date-time-functions.md"}
[ 0.062300875782966614, -0.03496021777391434, -0.03725738823413849, 0.07524675875902176, -0.09759880602359772, 0.03512944281101227, -0.001181969651952386, 0.0637054443359375, 0.011733205057680607, -0.007669472135603428, 0.018555620685219765, -0.1068357452750206, -0.01949441060423851, -0.0180...
f97fdb6b-9b9e-4bed-8c37-c8382d626c80
Introduced in: v1.1 Adds a specified number of months to a date, a date with time or a string-encoded date or date with time. Syntax sql addMonths(datetime, num) Arguments datetime โ€” Date or date with time to add specified number of months to. Date or Date32 or DateTime or DateTime64 or String num โ€” Number of months to add. (U)Int* or Float* Returned value Returns datetime plus num months Date or Date32 or DateTime or DateTime64 Examples Add months to different date types sql title=Query WITH toDate('2024-01-01') AS date, toDateTime('2024-01-01 00:00:00') AS date_time, '2024-01-01 00:00:00' AS date_time_string SELECT addMonths(date, 6) AS add_months_with_date, addMonths(date_time, 6) AS add_months_with_date_time, addMonths(date_time_string, 6) AS add_months_with_date_time_string response title=Response โ”Œโ”€add_months_with_dateโ”€โ”ฌโ”€add_months_with_date_timeโ”€โ”ฌโ”€add_months_with_date_time_stringโ”€โ” โ”‚ 2024-07-01 โ”‚ 2024-07-01 00:00:00 โ”‚ 2024-07-01 00:00:00.000 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Using alternative INTERVAL syntax sql title=Query SELECT dateAdd('1998-06-16'::Date, INTERVAL 10 month) response title=Response โ”Œโ”€plus(CAST('1โ‹ฏlMonth(10))โ”€โ” โ”‚ 1999-04-16 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ addNanoseconds {#addNanoseconds} Introduced in: v22.6 Adds a specified number of nanoseconds to a date with time or a string-encoded date with time. Syntax sql addNanoseconds(datetime, num) Arguments datetime โ€” Date with time to add specified number of nanoseconds to. DateTime or DateTime64 or String num โ€” Number of nanoseconds to add. (U)Int* or Float* Returned value Returns datetime plus num nanoseconds DateTime64 Examples Add nanoseconds to different date time types sql title=Query WITH toDateTime('2024-01-01 00:00:00') AS date_time, '2024-01-01 00:00:00' AS date_time_string SELECT addNanoseconds(date_time, 1000) AS add_nanoseconds_with_date_time, addNanoseconds(date_time_string, 1000) AS add_nanoseconds_with_date_time_string response title=Response โ”Œโ”€add_nanoseconds_with_date_timeโ”€โ”ฌโ”€add_nanoseconds_with_date_time_stringโ”€โ” โ”‚ 2024-01-01 00:00:00.000001000 โ”‚ 2024-01-01 00:00:00.000001000 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ Using alternative INTERVAL syntax sql title=Query SELECT dateAdd('1998-06-16'::DateTime, INTERVAL 1000 nanosecond) response title=Response โ”Œโ”€plus(CAST('199โ‹ฏosecond(1000))โ”€โ” โ”‚ 1998-06-16 00:00:00.000001000 โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ addQuarters {#addQuarters} Introduced in: v20.1 Adds a specified number of quarters to a date, a date with time or a string-encoded date or date with time. Syntax sql addQuarters(datetime, num) Arguments
{"source_file": "date-time-functions.md"}
[ 0.032196417450904846, -0.0740765631198883, -0.09280598908662796, 0.08589369803667068, -0.08261621743440628, 0.02307179942727089, -0.0362633541226387, 0.004795580171048641, -0.04177108034491539, 0.056370459496974945, 0.06959212571382523, -0.0828423947095871, -0.024509551003575325, -0.086196...