πŸ•·οΈ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 89 (from laksa008)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

πŸ“„
INDEXABLE
βœ…
CRAWLED
1 day ago
πŸ€–
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.1 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://clickhouse.com/docs/sql-reference/functions/other-functions
Last Crawled2026-04-20 09:17:38 (1 day ago)
First Indexed2025-02-20 22:30:08 (1 year ago)
HTTP Status Code200
Meta TitleOther functions | ClickHouse Docs
Meta DescriptionDocumentation for the "other" functions category
Meta Canonicalnull
Boilerpipe Text
Note The function documentation below is generated from the system.functions system table. FQDN ​ Introduced in: v20.1.0 Returns the fully qualified domain name of the ClickHouse server. Syntax FQDN ( ) Aliases : fullHostName Arguments None. Returned value Returns the fully qualified domain name of the ClickHouse server. String Examples Usage example Query SELECT fqdn ( ) Response β”Œβ”€FQDN()──────────────────────────┐ β”‚ clickhouse.us-east-2.internal β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ MACNumToString ​ Introduced in: v1.1.0 Interprets a UInt64 number as a MAC address in big endian format. Returns the corresponding MAC address in format AA:BB:CC:DD:EE:FF (colon-separated numbers in hexadecimal form) as string. Syntax MACNumToString ( num ) Arguments num β€” UInt64 number. UInt64 Returned value Returns a MAC address in format AA:BB:CC:DD:EE:FF. String Examples Usage example Query SELECT MACNumToString ( 149809441867716 ) AS mac_address ; Response β”Œβ”€mac_address───────┐ β”‚ 88:00:11:22:33:44 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ MACStringToNum ​ Introduced in: v1.1.0 The inverse function of MACNumToString. If the MAC address has an invalid format, it returns 0. Syntax MACStringToNum ( s ) Arguments s β€” MAC address string. String Returned value Returns a UInt64 number. UInt64 Examples Usage example Query SELECT MACStringToNum ( '01:02:03:04:05:06' ) AS mac_numeric ; Response 1108152157446 MACStringToOUI ​ Introduced in: v1.1.0 Given a MAC address in format AA:BB:CC:DD:EE:FF (colon-separated numbers in hexadecimal form), returns the first three octets as a UInt64 number. If the MAC address has an invalid format, it returns 0. Syntax MACStringToOUI ( s ) Arguments s β€” MAC address string. String Returned value First three octets as UInt64 number. UInt64 Examples Usage example Query SELECT MACStringToOUI ( '00:50:56:12:34:56' ) AS oui ; Response 20566 authenticatedUser ​ Introduced in: v25.11.0 If the session user has been switched using the EXECUTE AS command, this function returns the name of the original user that was used for authentication and creating the session. Alias: authUser() Syntax authenticatedUser ( ) Aliases : authUser Arguments None. Returned value The name of the authenticated user. String Examples Usage example Query EXECUTE as u1 ; SELECT currentUser ( ) , authenticatedUser ( ) ; Response β”Œβ”€currentUser()─┬─authenticatedUser()─┐ β”‚ u1 β”‚ default β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ bar ​ Introduced in: v1.1.0 Builds a bar chart. Draws a band with width proportional to (x - min) and equal to width characters when x = max. The band is drawn with accuracy to one eighth of a symbol. Syntax bar ( x , min , max [ , width ] ) Arguments x β€” Size to display. (U)Int* or Float* or Decimal min β€” The minimum value. (U)Int* or Float* or Decimal max β€” The maximum value. (U)Int* or Float* or Decimal width β€” Optional. The width of the bar in characters. The default is 80 . const (U)Int* or const Float* or const Decimal Returned value Returns a unicode-art bar string. String Examples Usage example Query SELECT toHour ( EventTime ) AS h , count ( ) AS c , bar ( c , 0 , 600000 , 20 ) AS bar FROM test . hits GROUP BY h ORDER BY h ASC Response β”Œβ”€β”€h─┬──────c─┬─bar────────────────┐ β”‚ 0 β”‚ 292907 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‹ β”‚ β”‚ 1 β”‚ 180563 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β”‚ β”‚ 2 β”‚ 114861 β”‚ β–ˆβ–ˆβ–ˆβ–‹ β”‚ β”‚ 3 β”‚ 85069 β”‚ β–ˆβ–ˆβ–‹ β”‚ β”‚ 4 β”‚ 68543 β”‚ β–ˆβ–ˆβ–Ž β”‚ β”‚ 5 β”‚ 78116 β”‚ β–ˆβ–ˆβ–Œ β”‚ β”‚ 6 β”‚ 113474 β”‚ β–ˆβ–ˆβ–ˆβ–‹ β”‚ β”‚ 7 β”‚ 170678 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‹ β”‚ β”‚ 8 β”‚ 278380 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Ž β”‚ β”‚ 9 β”‚ 391053 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β”‚ β”‚ 10 β”‚ 457681 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Ž β”‚ β”‚ 11 β”‚ 493667 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ– β”‚ β”‚ 12 β”‚ 509641 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Š β”‚ β”‚ 13 β”‚ 522947 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ– β”‚ β”‚ 14 β”‚ 539954 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Š β”‚ β”‚ 15 β”‚ 528460 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Œ β”‚ β”‚ 16 β”‚ 539201 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Š β”‚ β”‚ 17 β”‚ 523539 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ– β”‚ β”‚ 18 β”‚ 506467 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Š β”‚ β”‚ 19 β”‚ 520915 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Ž β”‚ β”‚ 20 β”‚ 521665 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ– β”‚ β”‚ 21 β”‚ 542078 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β”‚ β”‚ 22 β”‚ 493642 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ– β”‚ β”‚ 23 β”‚ 400397 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Ž β”‚ β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ blockNumber ​ Introduced in: v1.1.0 Returns a monotonically increasing sequence number of the block containing the row. The returned block number is updated on a best-effort basis, i.e. it may not be fully accurate. Syntax blockNumber ( ) Arguments None. Returned value Sequence number of the data block where the row is located. UInt64 Examples Basic usage Query SELECT blockNumber ( ) FROM ( SELECT * FROM system . numbers LIMIT 10 ) SETTINGS max_block_size = 2 Response β”Œβ”€blockNumber()─┐ β”‚ 7 β”‚ β”‚ 7 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€blockNumber()─┐ β”‚ 8 β”‚ β”‚ 8 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€blockNumber()─┐ β”‚ 9 β”‚ β”‚ 9 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€blockNumber()─┐ β”‚ 10 β”‚ β”‚ 10 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€blockNumber()─┐ β”‚ 11 β”‚ β”‚ 11 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ blockSerializedSize ​ Introduced in: v20.3.0 Returns the uncompressed size in bytes of a block of values on disk. Syntax blockSerializedSize ( x1 [ , x2 [ , . . . ] ] ) Arguments x1[, x2, ...] β€” Any number of values for which to get the uncompressed size of the block. Any Returned value Returns the number of bytes that will be written to disk for a block of values without compression. UInt64 Examples Usage example Query SELECT blockSerializedSize ( maxState ( 1 ) ) AS x ; Response β”Œβ”€x─┐ β”‚ 2 β”‚ β””β”€β”€β”€β”˜ blockSize ​ Introduced in: v1.1.0 In ClickHouse, queries are processed in blocks (chunks). This function returns the size (row count) of the block the function is called on. Syntax blockSize ( ) Arguments None. Returned value Returns the number of rows in the current block. UInt64 Examples Usage example Query SELECT blockSize ( ) FROM system . numbers LIMIT 5 Response β”Œβ”€blockSize()─┐ β”‚ 5 β”‚ β”‚ 5 β”‚ β”‚ 5 β”‚ β”‚ 5 β”‚ β”‚ 5 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ buildId ​ Introduced in: v20.5.0 Returns the build ID generated by a compiler for the running ClickHouse server binary. If executed in the context of a distributed table, this function generates a normal column with values relevant to each shard. Otherwise it produces a constant value. Syntax buildId ( ) Arguments None. Returned value Returns the build ID. String Examples Usage example Query SELECT buildId ( ) Response β”Œβ”€buildId()────────────────────────────────┐ β”‚ AB668BEF095FAA6BD26537F197AC2AF48A927FB4 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ byteSize ​ Introduced in: v21.1.0 Returns an estimation of the uncompressed byte size of its arguments in memory. For String arguments, the function returns the string length + 8 (length). If the function has multiple arguments, the function accumulates their byte sizes. Syntax byteSize ( arg1 [ , arg2 , . . . ] ) Arguments arg1[, arg2, ...] β€” Values of any data type for which to estimate the uncompressed byte size. Any Returned value Returns an estimation of the byte size of the arguments in memory. UInt64 Examples Usage example Query SELECT byteSize ( 'string' ) Response β”Œβ”€byteSize('string')─┐ β”‚ 15 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ Multiple arguments Query SELECT byteSize ( NULL , 1 , 0.3 , '' ) Response β”Œβ”€byteSize(NULL, 1, 0.3, '')─┐ β”‚ 19 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ catboostEvaluate ​ Introduced in: v22.9.0 Evaluate an external catboost model. CatBoost is an open-source gradient boosting library developed by Yandex for machine learning. Accepts a path to a catboost model and model arguments (features). Prerequisites Build the catboost evaluation library Before evaluating catboost models, the libcatboostmodel.<so|dylib> library must be made available. See CatBoost documentation how to compile it. Next, specify the path to libcatboostmodel.<so|dylib> in the clickhouse configuration: < clickhouse > ... < catboost_lib_path > /path/to/libcatboostmodel.so </ catboost_lib_path > ... </ clickhouse > For security and isolation reasons, the model evaluation does not run in the server process but in the clickhouse-library-bridge process. At the first execution of catboostEvaluate() , the server starts the library bridge process if it is not running already. Both processes communicate using a HTTP interface. By default, port 9012 is used. A different port can be specified as follows - this is useful if port 9012 is already assigned to a different service. < library_bridge > < port > 9019 </ port > </ library_bridge > Train a catboost model using libcatboost See Training and applying models for how to train catboost models from a training data set. Syntax catboostEvaluate ( path_to_model , feature_1 [ , feature_2 , . . . , feature_n ] ) Arguments path_to_model β€” Path to catboost model. const String feature β€” One or more model features/arguments. Float* Returned value Returns the model evaluation result. Float64 Examples catboostEvaluate Query SELECT catboostEvaluate ( '/root/occupy.bin' , Temperature , Humidity , Light , CO2 , HumidityRatio ) AS prediction FROM occupancy LIMIT 1 Response 4.695691092573497 colorOKLABToSRGB ​ Introduced in: v26.2.0 Converts a color from the OKLab perceptual color space to the sRGB color space. The input color is specified in the OKLab color space. If the input values are outside the typical OKLab ranges, the result is implementation-defined. OKLab uses three components: L: perceptual lightness (typically in the range [0..1]) a: green-red opponent axis b: blue-yellow opponent axis The a and b components are theoretically unbounded, but in practice are between -0.4 and 0.4. OKLab is designed to be perceptually uniform while remaining inexpensive to compute. The conversion is intended to be the inverse of colorSRGBToOKLAB and consists of the following stages: Conversion from OKLab to linear sRGB. Conversion from linear sRGB to gamma-encoded sRGB. The optional gamma argument specifies the exponent used when converting from linear sRGB to gamma-encoded RGB values. If not specified, a default gamma value is used for consistency with colorSRGBToOKLAB. For more information about the OKLab color space and its relationship to sRGB, see https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/color_value/oklab . Syntax colorOKLABToSRGB ( tuple [ , gamma ] ) Arguments tuple β€” A tuple of three numeric values L , a , b , where L is in the range [0...1] . Tuple(Float64, Float64, Float64) gamma β€” Optional. The exponent that is used to transform linear sRGB back to sRGB by applying (x ^ (1 / gamma)) * 255 for each channel x . Defaults to 2.2 . Float64 Returned value Returns a tuple (R, G, B) representing sRGB color values. Tuple(Float64, Float64, Float64) Examples Convert OKLAB to sRGB (Float) Query SELECT colorOKLABToSRGB ( ( 0.4466 , 0.0991 , 0.44 ) ) AS rgb ; Response β”Œβ”€rgb──────────────────────┐ β”‚ (198.07056923258935,0,0) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ Convert OKLAB to sRGB (UInt8) Query WITH colorOKLABToSRGB ( ( 0.7 , 0.1 , 0.54 ) ) AS t SELECT tuple ( toUInt8 ( t . 1 ) , toUInt8 ( t . 2 ) , toUInt8 ( t . 3 ) ) AS RGB ; Response β”Œβ”€RGB──────────┐ β”‚ (255,0,0) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ colorOKLCHToSRGB ​ Introduced in: v25.7.0 Converts a colour from the OKLCH perceptual colour space to the familiar sRGB colour space. If L is outside the range [0...1] , C is negative, or H is outside the range [0...360] , the result is implementation-defined. Note OKLCH is a cylindrical version of the OKLab colour space. It's three coordinates are L (the lightness in the range [0...1] ), C (chroma >= 0 ) and H (hue in degrees from [0...360] ). OKLab/OKLCH is designed to be perceptually uniform while remaining cheap to compute. The conversion is the inverse of colorSRGBToOKLCH : OKLCH to OKLab. OKLab to Linear sRGB Linear sRGB to sRGB The second argument gamma is used at the last stage. For references of colors in OKLCH space, and how they correspond to sRGB colors please see https://oklch.com/ . Syntax colorOKLCHToSRGB(tuple [, gamma]) Arguments tuple β€” A tuple of three numeric values L , C , H , where L is in the range [0...1] , C >= 0 and H is in the range [0...360] . Tuple(Float64, Float64, Float64) gamma β€” Optional. The exponent that is used to transform linear sRGB back to sRGB by applying (x ^ (1 / gamma)) * 255 for each channel x . Defaults to 2.2 . Float64 Returned value Returns a tuple (R, G, B) representing sRGB color values. Tuple(Float64, Float64, Float64) Examples Convert OKLCH to sRGB SELECT colorOKLCHToSRGB((0.6, 0.12, 40)) AS rgb; β”Œβ”€rgb───────────────────────────────────────────────────────┐ β”‚ (186.02058688365264,100.68677189684993,71.67819977081575) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ Convert OKLCH to sRGB (UInt8) WITH colorOKLCHToSRGB((0.6, 0.12, 40)) AS t SELECT tuple(toUInt8(t.1), toUInt8(t.2), toUInt8(t.3)) AS RGB; β”Œβ”€RGB──────────┐ β”‚ (186,100,71) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ colorSRGBToOKLAB ​ Introduced in: v26.2.0 Converts a colour encoded in the sRGB colour space to the perceptually uniform OKLAB colour space. If any input channel is outside [0...255] or the gamma value is non-positive, the behaviour is implementation-defined. Note OKLAB is a perceptually uniform color space. Its three coordinates are L (the lightness in the range [0...1] ), a (Green-Red axis) and b (Blue-Yellow axis) . OKLab is designed to be perceptually uniform while remaining cheap to compute. The conversion consists of two stages: sRGB to Linear sRGB Linear sRGB to OKLab Syntax colorSRGBToOKLAB(tuple[, gamma]) Arguments tuple β€” Tuple of three values R, G, B in the range [0...255] . Tuple(UInt8, UInt8, UInt8) gamma β€” Optional. Exponent that is used to linearize sRGB by applying (x / 255)^gamma to each channel x . Defaults to 2.2 . Float64 Returned value Returns a tuple (L, a, b) representing the OKLAB color space values. Tuple(Float64, Float64, Float64) Examples Convert sRGB to OKLAB SELECT colorSRGBToOKLAB((128, 64, 32), 2.2) AS lab; β”Œβ”€lab──────────────────────────────────────────────────────────┐ β”‚ (0.4436238384931984,0.07266246769242975,0.07500108778529994) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ colorSRGBToOKLCH ​ Introduced in: v25.7.0 Converts a colour encoded in the sRGB colour space to the perceptually uniform OKLCH colour space. If any input channel is outside [0...255] or the gamma value is non-positive, the behaviour is implementation-defined. Note OKLCH is a cylindrical version of the OKLab colour space. It's three coordinates are L (the lightness in the range [0...1] ), C (chroma >= 0 ) and H (the hue in degrees from [0...360] ). OKLab/OKLCH is designed to be perceptually uniform while remaining cheap to compute. The conversion consists of three stages: sRGB to Linear sRGB Linear sRGB to OKLab OKLab to OKLCH. For references of colors in the OKLCH space, and how they correspond to sRGB colors, please see https://OKLCH.com/ . Syntax colorSRGBToOKLCH(tuple[, gamma]) Arguments tuple β€” Tuple of three values R, G, B in the range [0...255] . Tuple(UInt8, UInt8, UInt8) gamma β€” Optional. Exponent that is used to linearize sRGB by applying (x / 255)^gamma to each channel x . Defaults to 2.2 . Float64 Returned value Returns a tuple (L, C, H) representing the OKLCH color space values. Tuple(Float64, Float64, Float64) Examples Convert sRGB to OKLCH SELECT colorSRGBToOKLCH((128, 64, 32), 2.2) AS lch; β”Œβ”€lch───────────────────────────────────────────────────────┐ β”‚ (0.4436238384931984,0.1044269954567863,45.90734548193018) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ connectionId ​ Introduced in: v21.3.0 Returns the connection ID of the client that submitted the current query. This function is most useful in debugging scenarios. It was created for compatibility with MySQL's CONNECTION_ID function. It is not typically used in production queries. Syntax connectionId() Arguments None. Returned value Returns the connection ID of the current client. UInt64 Examples Usage example SELECT connectionId(); β”Œβ”€connectionId()─┐ β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ countDigits ​ Introduced in: v20.8.0 Returns the number of decimal digits needed to represent a value. Note This function takes into account the scales of decimal values i.e., it calculates the result over the underlying integer type which is (value * scale) . For example: countDigits(42) = 2 countDigits(42.000) = 5 countDigits(0.04200) = 4 Tip You can check decimal overflow for Decimal64 with countDigits(x) > 18 , although it is slower than isDecimalOverflow . Syntax countDigits(x) Arguments x β€” An integer or decimal value. (U)Int* or Decimal Returned value Returns the number of digits needed to represent x . UInt8 Examples Usage example SELECT countDigits(toDecimal32(1, 9)), countDigits(toDecimal32(-1, 9)), countDigits(toDecimal64(1, 18)), countDigits(toDecimal64(-1, 18)), countDigits(toDecimal128(1, 38)), countDigits(toDecimal128(-1, 38)); β”Œβ”€countDigits(toDecimal32(1, 9))─┬─countDigits(toDecimal32(-1, 9))─┬─countDigits(toDecimal64(1, 18))─┬─countDigits(toDecimal64(-1, 18))─┬─countDigits(toDecimal128(1, 38))─┬─countDigits(toDecimal128(-1, 38))─┐ β”‚ 10 β”‚ 10 β”‚ 19 β”‚ 19 β”‚ 39 β”‚ 39 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ currentDatabase ​ Introduced in: v1.1.0 Returns the name of the current database. Useful in table engine parameters of CREATE TABLE queries where you need to specify the database. Also see the SET statement . Syntax currentDatabase() Aliases : current_database , SCHEMA , DATABASE Arguments None. Returned value Returns the current database name. String Examples Usage example SELECT currentDatabase() β”Œβ”€currentDatabase()─┐ β”‚ default β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ SQL standard syntax without parentheses SELECT CURRENT_DATABASE β”Œβ”€CURRENT_DATABASE─┐ β”‚ default β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ currentProfiles ​ Introduced in: v21.9.0 Returns an array of the setting profiles for the current user. Syntax currentProfiles() Arguments None. Returned value Returns an array of setting profiles for the current user. Array(String) Examples Usage example SELECT currentProfiles(); β”Œβ”€currentProfiles()─────────────────────────────┐ β”‚ ['default', 'readonly_user', 'web_analytics'] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ currentQueryID ​ Introduced in: v25.2.0 Returns current Query id. Syntax currentQueryID() Aliases : current_query_id Arguments None. Returned value Examples Example SELECT currentQueryID(); β”Œβ”€currentQueryID()─────────────────────┐ β”‚ 1280d0e8-1a08-4524-be6e-77975bb68e7d β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ currentRoles ​ Introduced in: v21.9.0 Returns an array of the roles which are assigned to the current user. Syntax currentRoles() Arguments None. Returned value Returns an array of the roles which are assigned to the current user. Array(String) Examples Usage example SELECT currentRoles(); β”Œβ”€currentRoles()─────────────────────────────────┐ β”‚ ['sql-console-role:jane.smith@clickhouse.com'] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ currentSchemas ​ Introduced in: v23.7.0 Same as function currentDatabase but accepts a boolean argument which is ignored returns the database name as an array with a single value. Function currentSchemas only exists for compatibility with PostgreSQL. Please use currentDatabase instead. Also see the SET statement . Syntax currentSchemas(bool) Aliases : current_schemas Arguments bool β€” A boolean value, which is ignored. Bool Returned value Returns a single-element array with the name of the current database. Array(String) Examples Usage example SELECT currentSchemas(true) β”Œβ”€currentSchemas(true)─┐ β”‚ ['default'] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ currentUser ​ Introduced in: v20.1.0 Returns the name of the current user. In case of a distributed query, the name of the user who initiated the query is returned. Syntax currentUser() Aliases : current_user , user Arguments None. Returned value Returns the name of the current user, otherwise the login of the user who initiated the query. String Examples Usage example SELECT currentUser() β”Œβ”€currentUser()─┐ β”‚ default β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ SQL standard syntax without parentheses SELECT CURRENT_USER β”Œβ”€CURRENT_USER─┐ β”‚ default β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ defaultProfiles ​ Introduced in: v21.9.0 Returns an array of default setting profile names for the current user. Syntax defaultProfiles() Arguments None. Returned value Returns an array of default setting profile names for the current user. Array(String) Examples Usage example SELECT defaultProfiles(); β”Œβ”€defaultProfiles()─┐ β”‚ ['default'] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ defaultRoles ​ Introduced in: v21.9.0 Returns an array of default roles for the current user. Syntax defaultRoles() Arguments None. Returned value Returns an array of default roles for the current user. Array(String) Examples Usage example SELECT defaultRoles(); β”Œβ”€defaultRoles()─────────────────────────────────┐ β”‚ ['sql-console-role:jane.smith@clickhouse.com'] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ defaultValueOfArgumentType ​ Introduced in: v1.1.0 Returns the default value for a given data type. Does not include default values for custom columns set by the user. Syntax defaultValueOfArgumentType(expression) Arguments expression β€” Arbitrary type of value or an expression that results in a value of an arbitrary type. Any Returned value Returns 0 for numbers, an empty string for strings or NULL for Nullable types. UInt8 or String or NULL Examples Usage example SELECT defaultValueOfArgumentType(CAST(1 AS Int8)); β”Œβ”€defaultValueOfArgumentType(CAST(1, 'Int8'))─┐ β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ Nullable example SELECT defaultValueOfArgumentType(CAST(1 AS Nullable(Int8))); β”Œβ”€defaultValueOfArgumentType(CAST(1, 'Nullable(Int8)'))─┐ β”‚ ᴺᡁᴸᴸ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ defaultValueOfTypeName ​ Introduced in: v1.1.0 Returns the default value for the given type name. Syntax defaultValueOfTypeName(type) Arguments type β€” A string representing a type name. String Returned value Returns the default value for the given type name: 0 for numbers, an empty string for strings, or NULL for Nullable UInt8 or String or NULL Examples Usage example SELECT defaultValueOfTypeName('Int8'); β”Œβ”€defaultValueOfTypeName('Int8')─┐ β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ Nullable example SELECT defaultValueOfTypeName('Nullable(Int8)'); β”Œβ”€defaultValueOfTypeName('Nullable(Int8)')─┐ β”‚ ᴺᡁᴸᴸ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ displayName ​ Introduced in: v22.11.0 Returns the value of display_name from config or the server's Fully Qualified Domain Name (FQDN) if not set. Syntax displayName() Arguments None. Returned value Returns the value of display_name from config or server FQDN if not set. String Examples Usage example SELECT displayName(); β”Œβ”€displayName()─┐ β”‚ production β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ dumpColumnStructure ​ Introduced in: v1.1.0 Outputs a detailed description of the internal structure of a column and its data type. Syntax dumpColumnStructure(x) Arguments x β€” Value for which to get the description of. Any Returned value Returns a description of the column structure used for representing the value. String Examples Usage example SELECT dumpColumnStructure(CAST('2018-01-01 01:02:03', 'DateTime')); β”Œβ”€dumpColumnStructure(CAST('2018-01-01 01:02:03', 'DateTime'))─┐ β”‚ DateTime, Const(size = 1, UInt32(size = 1)) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ enabledProfiles ​ Introduced in: v21.9.0 Returns an array of setting profile names which are enabled for the current user. Syntax enabledProfiles() Arguments None. Returned value Returns an array of setting profile names which are enabled for the current user. Array(String) Examples Usage example SELECT enabledProfiles(); β”Œβ”€enabledProfiles()─────────────────────────────────────────────────┐ β”‚ ['default', 'readonly_user', 'web_analytics', 'batch_processing'] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ enabledRoles ​ Introduced in: v21.9.0 Returns an array of the roles which are enabled for the current user. Syntax enabledRoles() Arguments None. Returned value Returns an array of role names which are enabled for the current user. Array(String) Examples Usage example SELECT enabledRoles(); β”Œβ”€enabledRoles()─────────────────────────────────────────────────┐ β”‚ ['general_data', 'sql-console-role:jane.smith@clickhouse.com'] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ errorCodeToName ​ Introduced in: v20.12.0 Returns the textual name of a numeric ClickHouse error code. The mapping from numeric error codes to error names is available here . Syntax errorCodeToName(error_code) Arguments error_code β€” ClickHouse error code. (U)Int* or Float* or Decimal Returned value Returns the textual name of error_code . String Examples Usage example SELECT errorCodeToName(252); β”Œβ”€errorCodeToName(252)─┐ β”‚ TOO_MANY_PARTS β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ file ​ Introduced in: v21.3.0 Reads a file as a string and loads the data into the specified column. The file content is not interpreted. Also see the file table function. Syntax file(path[, default]) Arguments path β€” The path of the file relative to the user_files_path . Supports wildcards * , ** , ? , {abc,def} and {N..M} where N , M are numbers and 'abc', 'def' are strings. String default β€” The value returned if the file does not exist or cannot be accessed. String or NULL Returned value Returns the file content as a string. String Examples Insert files into a table INSERT INTO table SELECT file('a.txt'), file('b.txt'); filesystemAvailable ​ Introduced in: v20.1.0 Returns the amount of free space in the filesystem hosting the database persistence. The returned value is always smaller than the total free space ( filesystemUnreserved ) because some space is reserved for the operating system. Syntax filesystemAvailable([disk_name]) Arguments disk_name β€” Optional. The disk name to find the amount of free space for. If omitted, uses the default disk. String or FixedString Returned value Returns the amount of remaining space available in bytes. UInt64 Examples Usage example SELECT formatReadableSize(filesystemAvailable()) AS "Available space"; β”Œβ”€Available space─┐ β”‚ 30.75 GiB β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ filesystemCapacity ​ Introduced in: v20.1.0 Returns the capacity of the filesystem in bytes. Needs the path to the data directory to be configured. Syntax filesystemCapacity([disk_name]) Arguments disk_name β€” Optional. The disk name to get the capacity for. If omitted, uses the default disk. String or FixedString Returned value Returns the capacity of the filesystem in bytes. UInt64 Examples Usage example SELECT formatReadableSize(filesystemCapacity()) AS "Capacity"; β”Œβ”€Capacity──┐ β”‚ 39.32 GiB β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ filesystemUnreserved ​ Introduced in: v22.12.0 Returns the total amount of free space on the filesystem hosting the database persistence (previously filesystemFree ). See also filesystemAvailable . Syntax filesystemUnreserved([disk_name]) Arguments disk_name β€” Optional. The disk name for which to find the total amount of free space. If omitted, uses the default disk. String or FixedString Returned value Returns the amount of free space in bytes. UInt64 Examples Usage example SELECT formatReadableSize(filesystemUnreserved()) AS "Free space"; β”Œβ”€Free space─┐ β”‚ 32.39 GiB β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ finalizeAggregation ​ Introduced in: v1.1.0 Given an aggregation state, this function returns the result of aggregation (or the finalized state when using a -State combinator). Syntax finalizeAggregation(state) Arguments state β€” State of aggregation. AggregateFunction Returned value Returns the finalized result of aggregation. Any Examples Usage example SELECT finalizeAggregation(arrayReduce('maxState', [1, 2, 3])); β”Œβ”€finalizeAggregation(arrayReduce('maxState', [1, 2, 3]))─┐ β”‚ 3 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ Combined with initializeAggregation WITH initializeAggregation('sumState', number) AS one_row_sum_state SELECT number, finalizeAggregation(one_row_sum_state) AS one_row_sum, runningAccumulate(one_row_sum_state) AS cumulative_sum FROM numbers(5); β”Œβ”€number─┬─one_row_sum─┬─cumulative_sum─┐ β”‚ 0 β”‚ 0 β”‚ 0 β”‚ β”‚ 1 β”‚ 1 β”‚ 1 β”‚ β”‚ 2 β”‚ 2 β”‚ 3 β”‚ β”‚ 3 β”‚ 3 β”‚ 6 β”‚ β”‚ 4 β”‚ 4 β”‚ 10 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ flipCoordinates ​ Introduced in: v25.10.0 Flips the x and y coordinates of geometric objects. This operation swaps latitude and longitude, which is useful for converting between different coordinate systems or correcting coordinate order. For a Point, it swaps the x and y coordinates. For complex geometries (LineString, Polygon, MultiPolygon, Ring, MultiLineString), it recursively applies the transformation to each coordinate pair. The function supports both individual geometry types (Point, Ring, Polygon, MultiPolygon, LineString, MultiLineString) and the Geometry variant type. Syntax flipCoordinates(geometry) Arguments geometry β€” The geometry to transform. Supported types: Point (Tuple(Float64, Float64)), Ring (Array(Point)), Polygon (Array(Ring)), MultiPolygon (Array(Polygon)), LineString (Array(Point)), MultiLineString (Array(LineString)), or Geometry (a variant containing any of these types). Returned value The geometry with flipped coordinates. The return type matches the input type. Point or Ring or Polygon or MultiPolygon or LineString or MultiLineString or Geometry Examples basic_point SELECT flipCoordinates((1.0, 2.0)); (2.0, 1.0) ring SELECT flipCoordinates([(1.0, 2.0), (3.0, 4.0)]); [(2.0, 1.0), (4.0, 3.0)] polygon SELECT flipCoordinates([[(1.0, 2.0), (3.0, 4.0)], [(5.0, 6.0), (7.0, 8.0)]]); [[(2.0, 1.0), (4.0, 3.0)], [(6.0, 5.0), (8.0, 7.0)]] geometry_wkt SELECT flipCoordinates(readWkt('POINT(10 20)')); (20, 10) geometry_polygon_wkt SELECT flipCoordinates(readWkt('POLYGON((0 0, 5 0, 5 5, 0 5, 0 0))')); [[(0, 0), (0, 5), (5, 5), (5, 0), (0, 0)]] formatQuery ​ Introduced in: v23.10.0 Returns a formatted, possibly multi-line, version of the given SQL query. Throws in case of a parsing error. [example:multiline] Syntax formatQuery(query) Arguments query β€” The SQL query to be formatted. String Returned value The formatted query String Examples multiline SELECT formatQuery('select a, b FRom tab WHERE a > 3 and b < 3'); SELECT a, b FROM tab WHERE (a > 3) AND (b < 3) formatQueryOrNull ​ Introduced in: v23.11.0 Returns a formatted, possibly multi-line, version of the given SQL query. Returns NULL in case of a parsing error. [example:multiline] Syntax formatQueryOrNull(query) Arguments query β€” The SQL query to be formatted. String Returned value The formatted query String Examples multiline SELECT formatQuery('select a, b FRom tab WHERE a > 3 and b < 3'); SELECT a, b FROM tab WHERE (a > 3) AND (b < 3) formatQuerySingleLine ​ Introduced in: v23.10.0 Like formatQuery() but the returned formatted string contains no line breaks. Throws in case of a parsing error. [example:multiline] Syntax formatQuerySingleLine(query) Arguments query β€” The SQL query to be formatted. String Returned value The formatted query String Examples multiline SELECT formatQuerySingleLine('select a, b FRom tab WHERE a > 3 and b < 3'); SELECT a, b FROM tab WHERE (a > 3) AND (b < 3) formatQuerySingleLineOrNull ​ Introduced in: v23.11.0 Like formatQuery() but the returned formatted string contains no line breaks. Returns NULL in case of a parsing error. [example:multiline] Syntax formatQuerySingleLineOrNull(query) Arguments query β€” The SQL query to be formatted. String Returned value The formatted query String Examples multiline SELECT formatQuerySingleLine('select a, b FRom tab WHERE a > 3 and b < 3'); SELECT a, b FROM tab WHERE (a > 3) AND (b < 3) formatReadableDecimalSize ​ Introduced in: v22.11.0 Given a size (number of bytes), this function returns a readable, rounded size with suffix (KB, MB, etc.) as a string. The opposite operations of this function are parseReadableSize . Syntax formatReadableDecimalSize(x) Arguments x β€” Size in bytes. UInt64 Returned value Returns a readable, rounded size with suffix as a string. String Examples Format file sizes SELECT arrayJoin([1, 1024, 1024*1024, 192851925]) AS filesize_bytes, formatReadableDecimalSize(filesize_bytes) AS filesize β”Œβ”€filesize_bytes─┬─filesize───┐ β”‚ 1 β”‚ 1.00 B β”‚ β”‚ 1024 β”‚ 1.02 KB β”‚ β”‚ 1048576 β”‚ 1.05 MB β”‚ β”‚ 192851925 β”‚ 192.85 MB β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ formatReadableQuantity ​ Introduced in: v20.10.0 Given a number, this function returns a rounded number with suffix (thousand, million, billion, etc.) as a string. This function accepts any numeric type as input, but internally it casts them to Float64 . Results might be suboptimal with large values. Syntax formatReadableQuantity(x) Arguments x β€” A number to format. UInt64 Returned value Returns a rounded number with suffix as a string. String Examples Format numbers with suffixes SELECT arrayJoin([1024, 1234 * 1000, (4567 * 1000) * 1000, 98765432101234]) AS number, formatReadableQuantity(number) AS number_for_humans β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€number─┬─number_for_humans─┐ β”‚ 1024 β”‚ 1.02 thousand β”‚ β”‚ 1234000 β”‚ 1.23 million β”‚ β”‚ 4567000000 β”‚ 4.57 billion β”‚ β”‚ 98765432101234 β”‚ 98.77 trillion β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ formatReadableSize ​ Introduced in: v1.1.0 Given a size (number of bytes), this function returns a readable, rounded size with suffix (KiB, MiB, etc.) as string. The opposite operations of this function are parseReadableSize , parseReadableSizeOrZero , and parseReadableSizeOrNull . This function accepts any numeric type as input, but internally it casts them to Float64 . Results might be suboptimal with large values. Syntax formatReadableSize(x) Aliases : FORMAT_BYTES Arguments x β€” Size in bytes. UInt64 Returned value Returns a readable, rounded size with suffix as a string. String Examples Format file sizes SELECT arrayJoin([1, 1024, 1024*1024, 192851925]) AS filesize_bytes, formatReadableSize(filesize_bytes) AS filesize β”Œβ”€filesize_bytes─┬─filesize───┐ β”‚ 1 β”‚ 1.00 B β”‚ β”‚ 1024 β”‚ 1.00 KiB β”‚ β”‚ 1048576 β”‚ 1.00 MiB β”‚ β”‚ 192851925 β”‚ 183.92 MiB β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ formatReadableTimeDelta ​ Introduced in: v20.12.0 Given a time interval (delta) in seconds, this function returns a time delta with year/month/day/hour/minute/second/millisecond/microsecond/nanosecond as a string. This function accepts any numeric type as input, but internally it casts them to Float64 . Results might be suboptimal with large values. Syntax formatReadableTimeDelta(column[, maximum_unit, minimum_unit]) Arguments column β€” A column with a numeric time delta. Float64 maximum_unit β€” Optional. Maximum unit to show. Acceptable values: nanoseconds , microseconds , milliseconds , seconds , minutes , hours , days , months , years . Default value: years . const String minimum_unit β€” Optional. Minimum unit to show. All smaller units are truncated. Acceptable values: nanoseconds , microseconds , milliseconds , seconds , minutes , hours , days , months , years . If explicitly specified value is bigger than maximum_unit , an exception will be thrown. Default value: seconds if maximum_unit is seconds or bigger, nanoseconds otherwise. const String Returned value Returns a time delta as a string. String Examples Usage example SELECT arrayJoin([100, 12345, 432546534]) AS elapsed, formatReadableTimeDelta(elapsed) AS time_delta β”Œβ”€β”€β”€β”€elapsed─┬─time_delta─────────────────────────────────────────────────────┐ β”‚ 100 β”‚ 1 minute and 40 seconds β”‚ β”‚ 12345 β”‚ 3 hours, 25 minutes and 45 seconds β”‚ β”‚ 432546534 β”‚ 13 years, 8 months, 17 days, 7 hours, 48 minutes and 54 secondsβ”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ With maximum unit SELECT arrayJoin([100, 12345, 432546534]) AS elapsed, formatReadableTimeDelta(elapsed, 'minutes') AS time_delta β”Œβ”€β”€β”€β”€elapsed─┬─time_delta─────────────────────────────────────────────────────┐ β”‚ 100 β”‚ 1 minute and 40 seconds β”‚ β”‚ 12345 β”‚ 205 minutes and 45 seconds β”‚ β”‚ 432546534 β”‚ 7209108 minutes and 54 seconds β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ fuzzQuery ​ Introduced in: v26.2.0 Parses the given query string and applies random AST mutations (fuzzing) to it. Returns the fuzzed query as a string. Non-deterministic: each call may produce a different result. Requires allow_fuzz_query_functions = 1 . Syntax fuzzQuery(query) Arguments query β€” The SQL query to be fuzzed. String Returned value The fuzzed query string String Examples basic SET allow_fuzz_query_functions = 1; SELECT fuzzQuery('SELECT 1'); generateRandomStructure ​ Introduced in: v23.5.0 Generates random table structure in the format column1_name column1_type, column2_name column2_type, ... . Syntax generateRandomStructure([number_of_columns, seed]) Arguments number_of_columns β€” The desired number of columns in the resultant table structure. If set to 0 or Null , the number of columns will be random from 1 to 128. Default value: Null . UInt64 seed β€” Random seed to produce stable results. If seed is not specified or set to Null , it is randomly generated. UInt64 Returned value Randomly generated table structure. String Examples Usage example SELECT generateRandomStructure() c1 Decimal32(5), c2 Date, c3 Tuple(LowCardinality(String), Int128, UInt64, UInt16, UInt8, IPv6), c4 Array(UInt128), c5 UInt32, c6 IPv4, c7 Decimal256(64), c8 Decimal128(3), c9 UInt256, c10 UInt64, c11 DateTime with specified number of columns SELECT generateRandomStructure(1) c1 Map(UInt256, UInt16) with specified seed SELECT generateRandomStructure(NULL, 33) c1 DateTime, c2 Enum8('c2V0' = 0, 'c2V1' = 1, 'c2V2' = 2, 'c2V3' = 3), c3 LowCardinality(Nullable(FixedString(30))), c4 Int16, c5 Enum8('c5V0' = 0, 'c5V1' = 1, 'c5V2' = 2, 'c5V3' = 3), c6 Nullable(UInt8), c7 String, c8 Nested(e1 IPv4, e2 UInt8, e3 UInt16, e4 UInt16, e5 Int32, e6 Map(Date, Decimal256(70))) generateSerialID ​ Introduced in: v25.1.0 Generates and returns sequential numbers starting from the previous counter value. This function takes a string argument - a series identifier, and an optional starting value. The server should be configured with Keeper. The series are stored in Keeper nodes under the path, which can be configured in series_keeper_path in the server configuration. Syntax generateSerialID(series_identifier[, start_value]) Arguments series_identifier β€” Series identifier const String start_value β€” Optional. Starting value for the counter. Defaults to 0. Note: this value is only used when creating a new series and is ignored if the series already exists UInt* Returned value Returns sequential numbers starting from the previous counter value. UInt64 Examples first call SELECT generateSerialID('id1') β”Œβ”€generateSerialID('id1')──┐ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ second call SELECT generateSerialID('id1') β”Œβ”€generateSerialID('id1')──┐ β”‚ 2 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ column call SELECT *, generateSerialID('id1') FROM test_table β”Œβ”€CounterID─┬─UserID─┬─ver─┬─generateSerialID('id1')──┐ β”‚ 1 β”‚ 3 β”‚ 3 β”‚ 3 β”‚ β”‚ 1 β”‚ 1 β”‚ 1 β”‚ 4 β”‚ β”‚ 1 β”‚ 2 β”‚ 2 β”‚ 5 β”‚ β”‚ 1 β”‚ 5 β”‚ 5 β”‚ 6 β”‚ β”‚ 1 β”‚ 4 β”‚ 4 β”‚ 7 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ with start value SELECT generateSerialID('id2', 100) β”Œβ”€generateSerialID('id2', 100)──┐ β”‚ 100 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ with start value second call SELECT generateSerialID('id2', 100) β”Œβ”€generateSerialID('id2', 100)──┐ β”‚ 101 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ Introduced in: v24.5.0 Gets the value of an HTTP header. If there is no such header or the current request is not performed via the HTTP interface, the function returns an empty string. Certain HTTP headers (e.g., Authentication and X-ClickHouse-* ) are restricted. Note Setting allow_get_client_http_header is required The function requires the setting allow_get_client_http_header to be enabled. The setting is not enabled by default for security reasons, because some headers, such as Cookie , could contain sensitive info. HTTP headers are case sensitive for this function. If the function is used in the context of a distributed query, it returns non-empty result only on the initiator node. Syntax getClientHTTPHeader(name) Arguments name β€” The HTTP header name. String Returned value Returns the value of the header. String Examples Usage example SELECT getClientHTTPHeader('Content-Type'); β”Œβ”€getClientHTTPHeader('Content-Type')─┐ β”‚ application/x-www-form-urlencoded β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ getMacro ​ Introduced in: v20.1.0 Returns the value of a macro from the server configuration file. Macros are defined in the <macros> section of the configuration file and can be used to distinguish servers by convenient names even if they have complicated hostnames. If the function is executed in the context of a distributed table, it generates a normal column with values relevant to each shard. Syntax getMacro(name) Arguments name β€” The name of the macro to retrieve. const String Returned value Returns the value of the specified macro. String Examples Basic usage SELECT getMacro('test'); β”Œβ”€getMacro('test')─┐ β”‚ Value β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ getMaxTableNameLengthForDatabase ​ Introduced in: v25.1.0 Returns the maximum table name length in a specified database. Syntax getMaxTableNameLengthForDatabase(database_name) Arguments database_name β€” The name of the specified database. String Returned value Returns the length of the maximum table name, an Integer Examples typical SELECT getMaxTableNameLengthForDatabase('default'); β”Œβ”€getMaxTableNameLengthForDatabase('default')─┐ β”‚ 206 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ getMergeTreeSetting ​ Introduced in: v25.6.0 Returns the current value of a MergeTree setting. Syntax getMergeTreeSetting(setting_name) Arguments setting_name β€” The setting name. String Returned value Returns the merge tree setting's current value. Examples Usage example SELECT getMergeTreeSetting('index_granularity'); β”Œβ”€getMergeTreeSetting('index_granularity')─┐ β”‚ 8192 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ getOSKernelVersion ​ Introduced in: v21.11.0 Returns a string with the OS kernel version. Syntax getOSKernelVersion() Arguments None. Returned value Returns the current OS kernel version. String Examples Usage example SELECT getOSKernelVersion(); β”Œβ”€getOSKernelVersion()────┐ β”‚ Linux 4.15.0-55-generic β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ getServerPort ​ Introduced in: v21.10.0 Returns the server's port number for a given protocol. Syntax getServerPort(port_name) Arguments port_name β€” The name of the port. String Returned value Returns the server port number. UInt16 Examples Usage example SELECT getServerPort('tcp_port'); β”Œβ”€getServerPort('tcp_port')─┐ β”‚ 9000 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ getServerSetting ​ Introduced in: v25.6.0 Returns the currently set value, given a server setting name. Syntax getServerSetting(setting_name') Arguments setting_name β€” The server setting name. String Returned value Returns the server setting's current value. Any Examples Usage example SELECT getServerSetting('allow_use_jemalloc_memory'); β”Œβ”€getServerSetting('allow_use_jemalloc_memory')─┐ β”‚ true β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ getSetting ​ Introduced in: v20.7.0 Returns the current value of a setting. Syntax getSetting(setting_name) Arguments setting_Name β€” The setting name. const String Returned value Returns the setting's current value. Any Examples Usage example SELECT getSetting('enable_analyzer'); SET enable_analyzer = false; SELECT getSetting('enable_analyzer'); β”Œβ”€getSetting('β‹―_analyzer')─┐ β”‚ true β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€getSetting('β‹―_analyzer')─┐ β”‚ false β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ getSettingOrDefault ​ Introduced in: v24.10.0 Returns the current value of a setting or returns the default value specified in the second argument if the setting is not set in the current profile. Syntax getSettingOrDefault(setting_name, default_value) Arguments setting_name β€” The setting name. String default_value β€” Value to return if custom_setting is not set. Value may be of any data type or Null. Returned value Returns the current value of the specified setting or default_value if the setting is not set. Examples Usage example SELECT getSettingOrDefault('custom_undef1', 'my_value'); SELECT getSettingOrDefault('custom_undef2', 100); SELECT getSettingOrDefault('custom_undef3', NULL); my_value 100 NULL getSizeOfEnumType ​ Introduced in: v1.1.0 Returns the number of fields in the given Enum . Syntax getSizeOfEnumType(x) Arguments x β€” Value of type Enum . Enum Returned value Returns the number of fields with Enum input values. UInt8/16 Examples Usage example SELECT getSizeOfEnumType(CAST('a' AS Enum8('a' = 1, 'b' = 2))) AS x; β”Œβ”€x─┐ β”‚ 2 β”‚ β””β”€β”€β”€β”˜ getSubcolumn ​ Introduced in: v23.3.0 Receives the expression or identifier and constant string with the name of subcolumn. Returns requested subcolumn extracted from the expression. Syntax getSubcolumn(nested_value, subcolumn_name) Arguments None. Returned value Examples getSubcolumn SELECT getSubcolumn(array_col, 'size0'), getSubcolumn(tuple_col, 'elem_name') getTypeSerializationStreams ​ Introduced in: v22.6.0 Enumerates stream paths of a data type. This function is intended for developmental use. Syntax getTypeSerializationStreams(col) Arguments col β€” Column or string representation of a data-type from which the data type will be detected. Any Returned value Returns an array with all the serialization sub-stream paths. Array(String) Examples tuple SELECT getTypeSerializationStreams(tuple('a', 1, 'b', 2)) ['{TupleElement(1), Regular}','{TupleElement(2), Regular}','{TupleElement(3), Regular}','{TupleElement(4), Regular}'] map SELECT getTypeSerializationStreams('Map(String, Int64)') ['{ArraySizes}','{ArrayElements, TupleElement(keys), Regular}','{ArrayElements, TupleElement(values), Regular}'] globalVariable ​ Introduced in: v20.5.0 Takes a constant string argument and returns the value of the global variable with that name. This function is intended for compatibility with MySQL and not needed or useful for normal operation of ClickHouse. Only few dummy global variables are defined. Syntax globalVariable(name) Arguments name β€” Global variable name. String Returned value Returns the value of variable name . Any Examples globalVariable SELECT globalVariable('max_allowed_packet') 67108864 hasColumnInTable ​ Introduced in: v1.1.0 Checks if a specific column exists in a database table. For elements in a nested data structure, the function checks for the existence of a column. For the nested data structure itself, the function returns 0 . Syntax hasColumnInTable([hostname[, username[, password]],]database, table, column) Arguments database β€” Name of the database. const String table β€” Name of the table. const String column β€” Name of the column. const String hostname β€” Optional. Remote server name to perform the check on. const String username β€” Optional. Username for remote server. const String password β€” Optional. Password for remote server. const String Returned value Returns 1 if the given column exists, 0 otherwise. UInt8 Examples Check an existing column SELECT hasColumnInTable('system','metrics','metric') 1 Check a non-existing column SELECT hasColumnInTable('system','metrics','non-existing_column') 0 hasThreadFuzzer ​ Introduced in: v20.6.0 Returns whether the thread fuzzer is enabled. THis function is only useful for testing and debugging. Syntax hasThreadFuzzer() Arguments None. Returned value Returns whether Thread Fuzzer is effective. UInt8 Examples Check Thread Fuzzer status SELECT hasThreadFuzzer() β”Œβ”€hasThreadFuzzer()─┐ β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ hostName ​ Introduced in: v20.5.0 Returns the name of the host on which this function was executed. If the function executes on a remote server (distributed processing), the remote server name is returned. If the function executes in the context of a distributed table, it generates a normal column with values relevant to each shard. Otherwise it produces a constant value. Syntax hostName() Aliases : hostname Arguments None. Returned value Returns the host name. String Examples Usage example SELECT hostName() β”Œβ”€hostName()─┐ β”‚ clickhouse β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ icebergBucket ​ Introduced in: v25.5.0 Implements logic for the iceberg bucket transform Syntax icebergBucket(N, value) Arguments N β€” The number of buckets, modulo. const (U)Int* value β€” The source value to transform. (U)Int* or Bool or Decimal or Float* or String or FixedString or UUID or Date or Time or DateTime Returned value Returns a 32-bit hash of the source value. Int32 Examples Example SELECT icebergBucket(5, 1.0 :: Float32) 4 icebergTruncate ​ Introduced in: v25.3.0 Implements logic of iceberg truncate transform: https://iceberg.apache.org/spec/#truncate-transform-details . Syntax icebergTruncate(N, value) Arguments value β€” The value to transform. String or (U)Int* or Decimal Returned value The same type as the argument Examples Example SELECT icebergTruncate(3, 'iceberg') ice identity ​ Introduced in: v1.1.0 This function returns the argument you pass to it, which is useful for debugging and testing. It lets you bypass index usage to see full scan performance instead. The query analyzer ignores anything inside identity functions when looking for indexes to use, and it also disables constant folding. Syntax identity(x) Arguments x β€” Input value. Any Returned value Returns the input value unchanged. Any Examples Usage example SELECT identity(42) 42 ignore ​ Introduced in: v1.1.0 Accepts arbitrary arguments and unconditionally returns 0 . Syntax ignore(x) Arguments x β€” An input value which is unused and passed only so as to avoid a syntax error. Any Returned value Always returns 0 . UInt8 Examples Usage example SELECT ignore(0, 'ClickHouse', NULL) β”Œβ”€ignore(0, 'ClickHouse', NULL)─┐ β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ indexHint ​ Introduced in: v1.1.0 This function is intended for debugging and introspection. It ignores its argument and always returns 1. The arguments are not evaluated. During index analysis, the argument of this function is assumed to not be wrapped in indexHint . This allows you to select data in index ranges by the corresponding condition but without further filtering by this condition. The index in ClickHouse is sparse and using indexHint will yield more data than specifying the same condition directly. Explanation Note: It is not possible to optimize a query with the indexHint function. The indexHint function does not optimize the query, as it does not provide any additional information for the query analysis. Having an expression inside the indexHint function is not anyhow better than without the indexHint function. The indexHint function can be used only for introspection and debugging purposes and it does not improve performance. If you see the usage of indexHint by anyone other than ClickHouse contributors, it is likely a mistake and you should remove it. Syntax indexHint(expression) Arguments expression β€” Any expression for index range selection. Expression Returned value Returns 1 in all cases. UInt8 Examples Usage example with date filtering SELECT FlightDate AS k, count() FROM ontime WHERE indexHint(k = '2025-09-15') GROUP BY k ORDER BY k ASC; β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€k─┬─count()─┐ β”‚ 2025-09-14 β”‚ 7071 β”‚ β”‚ 2025-09-15 β”‚ 16428 β”‚ β”‚ 2025-09-16 β”‚ 1077 β”‚ β”‚ 2025-09-30 β”‚ 8167 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ initialQueryID ​ Introduced in: v1.1.0 Returns the ID of the initial current query. Other parameters of a query can be extracted from field initial_query_id in system.query_log . In contrast to queryID function, initialQueryID returns the same results on different shards. Syntax initialQueryID() Aliases : initial_query_id Arguments None. Returned value Returns the ID of the initial current query. String Examples Usage example CREATE TABLE tmp (str String) ENGINE = Log; INSERT INTO tmp (*) VALUES ('a'); SELECT count(DISTINCT t) FROM (SELECT initialQueryID() AS t FROM remote('127.0.0.{1..3}', currentDatabase(), 'tmp') GROUP BY queryID()); β”Œβ”€count(DISTINCT t)─┐ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ initialQueryStartTime ​ Introduced in: v25.4.0 Returns the start time of the initial current query. initialQueryStartTime returns the same results on different shards. Syntax initialQueryStartTime() Aliases : initial_query_start_time Arguments None. Returned value Returns the start time of the initial current query. DateTime Examples Usage example CREATE TABLE tmp (str String) ENGINE = Log; INSERT INTO tmp (*) VALUES ('a'); SELECT count(DISTINCT t) FROM (SELECT initialQueryStartTime() AS t FROM remote('127.0.0.{1..3}', currentDatabase(), 'tmp') GROUP BY queryID()); β”Œβ”€count(DISTINCT t)─┐ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ initializeAggregation ​ Introduced in: v20.6.0 Calculates the result of an aggregate function based on a single value. This function can be used to initialize aggregate functions with combinator -State . You can create states of aggregate functions and insert them to columns of type AggregateFunction or use initialized aggregates as default values. Syntax initializeAggregation(aggregate_function, arg1[, arg2, ...]) Arguments aggregate_function β€” Name of the aggregation function to initialize. String arg1[, arg2, ...] β€” Arguments of the aggregate function. Any Returned value Returns the result of aggregation for every row passed to the function. The return type is the same as the return type of the function that initializeAggregation takes as a first argument. Any Examples Basic usage with uniqState SELECT uniqMerge(state) FROM (SELECT initializeAggregation('uniqState', number % 3) AS state FROM numbers(10000)); β”Œβ”€uniqMerge(state)─┐ β”‚ 3 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ Usage with sumState and finalizeAggregation SELECT finalizeAggregation(state), toTypeName(state) FROM (SELECT initializeAggregation('sumState', number % 3) AS state FROM numbers(5)); β”Œβ”€finalizeAggregation(state)─┬─toTypeName(state)─────────────┐ β”‚ 0 β”‚ AggregateFunction(sum, UInt8) β”‚ β”‚ 1 β”‚ AggregateFunction(sum, UInt8) β”‚ β”‚ 2 β”‚ AggregateFunction(sum, UInt8) β”‚ β”‚ 0 β”‚ AggregateFunction(sum, UInt8) β”‚ β”‚ 1 β”‚ AggregateFunction(sum, UInt8) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ isConstant ​ Introduced in: v20.3.0 Returns whether the argument is a constant expression. A constant expression is an expression whose result is known during query analysis, i.e. before execution. For example, expressions over literals are constant expressions. This function is mostly intended for development, debugging and demonstration. Syntax isConstant(x) Arguments x β€” An expression to check. Any Returned value Returns 1 if x is constant, 0 if x is non-constant. UInt8 Examples Constant expression SELECT isConstant(x + 1) FROM (SELECT 43 AS x) β”Œβ”€isConstant(plus(x, 1))─┐ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ Constant with function WITH 3.14 AS pi SELECT isConstant(cos(pi)) β”Œβ”€isConstant(cos(pi))─┐ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ Non-constant expression SELECT isConstant(number) FROM numbers(1) β”Œβ”€isConstant(number)─┐ β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ Behavior of the now() function SELECT isConstant(now()) β”Œβ”€isConstant(now())─┐ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ isDecimalOverflow ​ Introduced in: v20.8.0 Checks if a decimal number has too many digits to fit properly in a Decimal data type with given precision. Syntax isDecimalOverflow(value[, precision]) Arguments value β€” Decimal value to check. Decimal precision β€” Optional. The precision of the Decimal type. If omitted, the initial precision of the first argument is used. UInt8 Returned value Returns 1 if the decimal value has more digits than allowed by its precision, 0 if the decimal value satisfies the specified precision. UInt8 Examples Usage example SELECT isDecimalOverflow(toDecimal32(1000000000, 0), 9), isDecimalOverflow(toDecimal32(1000000000, 0)), isDecimalOverflow(toDecimal32(-1000000000, 0), 9), isDecimalOverflow(toDecimal32(-1000000000, 0)); β”Œβ”€isDecimalOverflow(toDecimal32(1000000000, 0), 9)─┬─isDecimalOverflow(toDecimal32(1000000000, 0))─┬─isDecimalOverflow(toDecimal32(-1000000000, 0), 9)─┬─isDecimalOverflow(toDecimal32(-1000000000, 0))─┐ β”‚ 1 β”‚ 1 β”‚ 1 β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ joinGet ​ Introduced in: v18.16.0 Allows you to extract data from a table the same way as from a dictionary. Gets data from Join tables using the specified join key. Note Only supports tables created with the ENGINE = Join(ANY, LEFT, <join_keys>) statement . Syntax joinGet(join_storage_table_name, value_column, join_keys) Arguments join_storage_table_name β€” An identifier which indicates where to perform the search. The identifier is searched in the default database (see parameter default_database in the config file). To override the default database, use the USE database_name query or specify the database and the table through a dot, like database_name.table_name . String value_column β€” The name of the column of the table that contains required data. const String join_keys β€” A list of join keys. Any Returned value Returns list of values corresponded to list of keys. Any Examples Usage example CREATE TABLE db_test.id_val(`id` UInt32, `val` UInt32) ENGINE = Join(ANY, LEFT, id); INSERT INTO db_test.id_val VALUES (1,11)(2,12)(4,13); SELECT joinGet(db_test.id_val, 'val', toUInt32(1)); β”Œβ”€joinGet(db_test.id_val, 'val', toUInt32(1))─┐ β”‚ 11 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ Usage with table from current database USE db_test; SELECT joinGet(id_val, 'val', toUInt32(2)); β”Œβ”€joinGet(id_val, 'val', toUInt32(2))─┐ β”‚ 12 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ Using arrays as join keys CREATE TABLE some_table (id1 UInt32, id2 UInt32, name String) ENGINE = Join(ANY, LEFT, id1, id2); INSERT INTO some_table VALUES (1, 11, 'a') (2, 12, 'b') (3, 13, 'c'); SELECT joinGet(some_table, 'name', 1, 11); β”Œβ”€joinGet(some_table, 'name', 1, 11)─┐ β”‚ a β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ joinGetOrNull ​ Introduced in: v20.4.0 Allows you to extract data from a table the same way as from a dictionary. Gets data from Join tables using the specified join key. Unlike joinGet it returns NULL when the key is missing. Note Only supports tables created with the ENGINE = Join(ANY, LEFT, <join_keys>) statement . Syntax joinGetOrNull(join_storage_table_name, value_column, join_keys) Arguments join_storage_table_name β€” An identifier which indicates where to perform the search. The identifier is searched in the default database (see parameter default_database in the config file). To override the default database, use the USE database_name query or specify the database and the table through a dot, like database_name.table_name . String value_column β€” The name of the column of the table that contains required data. const String join_keys β€” A list of join keys. Any Returned value Returns a list of values corresponding to the list of keys, or NULL if a key is not found. Any Examples Usage example CREATE TABLE db_test.id_val(`id` UInt32, `val` UInt32) ENGINE = Join(ANY, LEFT, id); INSERT INTO db_test.id_val VALUES (1,11)(2,12)(4,13); SELECT joinGetOrNull(db_test.id_val, 'val', toUInt32(1)), joinGetOrNull(db_test.id_val, 'val', toUInt32(999)); β”Œβ”€joinGetOrNull(db_test.id_val, 'val', toUInt32(1))─┬─joinGetOrNull(db_test.id_val, 'val', toUInt32(999))─┐ β”‚ 11 β”‚ ᴺᡁᴸᴸ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ lowCardinalityIndices ​ Introduced in: v18.12.0 Returns the position of a value in the dictionary of a LowCardinality column. Positions start at 1. Since LowCardinality have per-part dictionaries, this function may return different positions for the same value in different parts. Syntax lowCardinalityIndices(col) Arguments col β€” A low cardinality column. LowCardinality Returned value The position of the value in the dictionary of the current part. UInt64 Examples Usage examples DROP TABLE IF EXISTS test; CREATE TABLE test (s LowCardinality(String)) ENGINE = Memory; -- create two parts: INSERT INTO test VALUES ('ab'), ('cd'), ('ab'), ('ab'), ('df'); INSERT INTO test VALUES ('ef'), ('cd'), ('ab'), ('cd'), ('ef'); SELECT s, lowCardinalityIndices(s) FROM test; β”Œβ”€s──┬─lowCardinalityIndices(s)─┐ β”‚ ab β”‚ 1 β”‚ β”‚ cd β”‚ 2 β”‚ β”‚ ab β”‚ 1 β”‚ β”‚ ab β”‚ 1 β”‚ β”‚ df β”‚ 3 β”‚ β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€s──┬─lowCardinalityIndices(s)─┐ β”‚ ef β”‚ 1 β”‚ β”‚ cd β”‚ 2 β”‚ β”‚ ab β”‚ 3 β”‚ β”‚ cd β”‚ 2 β”‚ β”‚ ef β”‚ 1 β”‚ β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ lowCardinalityKeys ​ Introduced in: v18.12.0 Returns the dictionary values of a LowCardinality column. If the block is smaller or larger than the dictionary size, the result will be truncated or extended with default values. Since LowCardinality have per-part dictionaries, this function may return different dictionary values in different parts. Syntax lowCardinalityKeys(col) Arguments col β€” A low cardinality column. LowCardinality Returned value Returns the dictionary keys. UInt64 Examples lowCardinalityKeys DROP TABLE IF EXISTS test; CREATE TABLE test (s LowCardinality(String)) ENGINE = Memory; -- create two parts: INSERT INTO test VALUES ('ab'), ('cd'), ('ab'), ('ab'), ('df'); INSERT INTO test VALUES ('ef'), ('cd'), ('ab'), ('cd'), ('ef'); SELECT s, lowCardinalityKeys(s) FROM test; β”Œβ”€s──┬─lowCardinalityKeys(s)─┐ β”‚ ef β”‚ β”‚ β”‚ cd β”‚ ef β”‚ β”‚ ab β”‚ cd β”‚ β”‚ cd β”‚ ab β”‚ β”‚ ef β”‚ β”‚ β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€s──┬─lowCardinalityKeys(s)─┐ β”‚ ab β”‚ β”‚ β”‚ cd β”‚ ab β”‚ β”‚ ab β”‚ cd β”‚ β”‚ ab β”‚ df β”‚ β”‚ df β”‚ β”‚ β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ materialize ​ Introduced in: v1.1.0 Turns a constant into a full column containing a single value. Full columns and constants are represented differently in memory. Functions usually execute different code for normal and constant arguments, although the result should typically be the same. This function can be used to debug this behavior. Syntax materialize(x) Arguments x β€” A constant. Any Returned value Returns a full column containing the constant value. Any Examples Usage example -- In the example below the `countMatches` function expects a constant second argument. -- This behaviour can be debugged by using the `materialize` function to turn a constant into a full column, -- verifying that the function throws an error for a non-constant argument. SELECT countMatches('foobarfoo', 'foo'); SELECT countMatches('foobarfoo', materialize('foo')); 2 Code: 44. DB::Exception: Received from localhost:9000. DB::Exception: Illegal type of argument #2 'pattern' of function countMatches, expected constant String, got String minSampleSizeContinuous ​ Introduced in: v23.10.0 Calculates the minimum required sample size for an A/B test comparing means of a continuous metric in two samples. Uses the formula described in this article . Assumes equal sizes of treatment and control groups. Returns the required sample size for one group (i.e. the sample size required for the whole experiment is twice the returned value). Also assumes equal variance of the test metric in treatment and control groups. Syntax minSampleSizeContinuous(baseline, sigma, mde, power, alpha) Aliases : minSampleSizeContinous Arguments baseline β€” Baseline value of a metric. (U)Int* or Float* sigma β€” Baseline standard deviation of a metric. (U)Int* or Float* mde β€” Minimum detectable effect (MDE) as percentage of the baseline value (e.g. for a baseline value 112.25 the MDE 0.03 means an expected change to 112.25 Β± 112.25*0.03). (U)Int* or Float* power β€” Required statistical power of a test (1 - probability of Type II error). (U)Int* or Float* alpha β€” Required significance level of a test (probability of Type I error). (U)Int* or Float* Returned value Returns a named Tuple with 3 elements: minimum_sample_size , detect_range_lower and detect_range_upper . These are respectively: the required sample size, the lower bound of the range of values not detectable with the returned required sample size, calculated as baseline * (1 - mde) , and the upper bound of the range of values not detectable with the returned required sample size, calculated as baseline * (1 + mde) (Float64). Tuple(Float64, Float64, Float64) Examples minSampleSizeContinuous SELECT minSampleSizeContinuous(112.25, 21.1, 0.03, 0.80, 0.05) AS sample_size (616.2931945826209,108.8825,115.6175) minSampleSizeConversion ​ Introduced in: v22.6.0 Calculates minimum required sample size for an A/B test comparing conversions (proportions) in two samples. Uses the formula described in this article . Assumes equal sizes of treatment and control groups. Returns the sample size required for one group (i.e. the sample size required for the whole experiment is twice the returned value). Syntax minSampleSizeConversion(baseline, mde, power, alpha) Arguments baseline β€” Baseline conversion. Float* mde β€” Minimum detectable effect (MDE) as percentage points (e.g. for a baseline conversion 0.25 the MDE 0.03 means an expected change to 0.25 Β± 0.03). Float* power β€” Required statistical power of a test (1 - probability of Type II error). Float* alpha β€” Required significance level of a test (probability of Type I error). Float* Returned value Returns a named Tuple with 3 elements: minimum_sample_size , detect_range_lower , detect_range_upper . These are, respectively: the required sample size, the lower bound of the range of values not detectable with the returned required sample size, calculated as baseline - mde , the upper bound of the range of values not detectable with the returned required sample size, calculated as baseline + mde . Tuple(Float64, Float64, Float64) Examples minSampleSizeConversion SELECT minSampleSizeConversion(0.25, 0.03, 0.80, 0.05) AS sample_size (3396.077603219163,0.22,0.28) neighbor ​ Introduced in: v20.1.0 Returns a value from a column at a specified offset from the current row. This function is deprecated and error-prone because it operates on the physical order of data blocks which may not correspond to the logical order expected by users. Consider using proper window functions instead. The function can be enabled by setting allow_deprecated_error_prone_window_functions = 1 . Syntax neighbor(column, offset[, default_value]) Arguments column β€” The source column. Any offset β€” The offset from the current row. Positive values look forward, negative values look backward. Integer default_value β€” Optional. The value to return if the offset goes beyond the data bounds. If not specified, uses the default value for the column type. Any Returned value Returns a value from the specified offset, or default if out of bounds. Any Examples Usage example SELECT number, neighbor(number, 2) FROM system.numbers LIMIT 10; β”Œβ”€number─┬─neighbor(number, 2)─┐ β”‚ 0 β”‚ 2 β”‚ β”‚ 1 β”‚ 3 β”‚ β”‚ 2 β”‚ 4 β”‚ β”‚ 3 β”‚ 5 β”‚ β”‚ 4 β”‚ 6 β”‚ β”‚ 5 β”‚ 7 β”‚ β”‚ 6 β”‚ 8 β”‚ β”‚ 7 β”‚ 9 β”‚ β”‚ 8 β”‚ 0 β”‚ β”‚ 9 β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ With default value SELECT number, neighbor(number, 2, 999) FROM system.numbers LIMIT 10; β”Œβ”€number─┬─neighbor(number, 2, 999)─┐ β”‚ 0 β”‚ 2 β”‚ β”‚ 1 β”‚ 3 β”‚ β”‚ 2 β”‚ 4 β”‚ β”‚ 3 β”‚ 5 β”‚ β”‚ 4 β”‚ 6 β”‚ β”‚ 5 β”‚ 7 β”‚ β”‚ 6 β”‚ 8 β”‚ β”‚ 7 β”‚ 9 β”‚ β”‚ 8 β”‚ 999 β”‚ β”‚ 9 β”‚ 999 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ normalizeQuery ​ Introduced in: v20.8.0 Replaces literals, sequences of literals and complex aliases (containing whitespace, more than two digits or at least 36 bytes long such as UUIDs) with placeholder ? . Syntax normalizeQuery(x) Arguments x β€” Sequence of characters. String Returned value Returns the given sequence of characters with placeholders. String Examples Usage example SELECT normalizeQuery('[1, 2, 3, x]') AS query β”Œβ”€query────┐ β”‚ [?.., x] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ normalizeQueryKeepNames ​ Introduced in: v21.2.0 Replaces literals and sequences of literals with placeholder ? but does not replace complex aliases (containing whitespace, more than two digits or at least 36 bytes long such as UUIDs). This helps better analyze complex query logs. Syntax normalizeQueryKeepNames(x) Arguments x β€” Sequence of characters. String Returned value Returns the given sequence of characters with placeholders. String Examples Usage example SELECT normalizeQuery('SELECT 1 AS aComplexName123'), normalizeQueryKeepNames('SELECT 1 AS aComplexName123') β”Œβ”€normalizeQuery('SELECT 1 AS aComplexName123')─┬─normalizeQueryKeepNames('SELECT 1 AS aComplexName123')─┐ β”‚ SELECT ? AS `?` β”‚ SELECT ? AS aComplexName123 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ normalizedQueryHash ​ Introduced in: v20.8.0 Returns identical 64 bit hash values without the values of literals for similar queries. Can be helpful in analyzing query logs. Syntax normalizedQueryHash(x) Arguments x β€” Sequence of characters. String Returned value Returns a 64 bit hash value. UInt64 Examples Usage example SELECT normalizedQueryHash('SELECT 1 AS `xyz`') != normalizedQueryHash('SELECT 1 AS `abc`') AS res β”Œβ”€res─┐ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”˜ normalizedQueryHashKeepNames ​ Introduced in: v21.2.0 Like normalizedQueryHash it returns identical 64 bit hash values without the values of literals for similar queries, but it does not replace complex aliases (containing whitespace, more than two digits or at least 36 bytes long such as UUIDs) with a placeholder before hashing. Can be helpful in analyzing query logs. Syntax normalizedQueryHashKeepNames(x) Arguments x β€” Sequence of characters. String Returned value Returns a 64 bit hash value. UInt64 Examples Usage example SELECT normalizedQueryHash('SELECT 1 AS `xyz123`') != normalizedQueryHash('SELECT 1 AS `abc123`') AS normalizedQueryHash; SELECT normalizedQueryHashKeepNames('SELECT 1 AS `xyz123`') != normalizedQueryHashKeepNames('SELECT 1 AS `abc123`') AS normalizedQueryHashKeepNames; β”Œβ”€normalizedQueryHash─┐ β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€normalizedQueryHashKeepNames─┐ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ parseReadableSize ​ Introduced in: v24.6.0 Given a string containing a byte size and B , KiB , KB , MiB , MB , etc. as a unit (i.e. ISO/IEC 80000-13 or decimal byte unit), this function returns the corresponding number of bytes. If the function is unable to parse the input value, it throws an exception. The inverse operations of this function are formatReadableSize and formatReadableDecimalSize . Syntax parseReadableSize(x) Arguments x β€” Readable size with ISO/IEC 80000-13 or decimal byte unit. String Returned value Returns the number of bytes, rounded up to the nearest integer. UInt64 Examples Usage example SELECT arrayJoin(['1 B', '1 KiB', '3 MB', '5.314 KiB']) AS readable_sizes, parseReadableSize(readable_sizes) AS sizes; β”Œβ”€readable_sizes─┬───sizes─┐ β”‚ 1 B β”‚ 1 β”‚ β”‚ 1 KiB β”‚ 1024 β”‚ β”‚ 3 MB β”‚ 3000000 β”‚ β”‚ 5.314 KiB β”‚ 5442 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ parseReadableSizeOrNull ​ Introduced in: v24.6.0 Given a string containing a byte size and B , KiB , KB , MiB , MB , etc. as a unit (i.e. ISO/IEC 80000-13 or decimal byte unit), this function returns the corresponding number of bytes. If the function is unable to parse the input value, it returns NULL . The inverse operations of this function are formatReadableSize and formatReadableDecimalSize . Syntax parseReadableSizeOrNull(x) Arguments x β€” Readable size with ISO/IEC 80000-13 or decimal byte unit. String Returned value Returns the number of bytes, rounded up to the nearest integer, or NULL if unable to parse the input Nullable(UInt64) Examples Usage example SELECT arrayJoin(['1 B', '1 KiB', '3 MB', '5.314 KiB', 'invalid']) AS readable_sizes, parseReadableSizeOrNull(readable_sizes) AS sizes; β”Œβ”€readable_sizes─┬───sizes─┐ β”‚ 1 B β”‚ 1 β”‚ β”‚ 1 KiB β”‚ 1024 β”‚ β”‚ 3 MB β”‚ 3000000 β”‚ β”‚ 5.314 KiB β”‚ 5442 β”‚ β”‚ invalid β”‚ ᴺᡁᴸᴸ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ parseReadableSizeOrZero ​ Introduced in: v24.6.0 Given a string containing a byte size and B , KiB , KB , MiB , MB , etc. as a unit (i.e. ISO/IEC 80000-13 or decimal byte unit), this function returns the corresponding number of bytes. If the function is unable to parse the input value, it returns 0 . The inverse operations of this function are formatReadableSize and formatReadableDecimalSize . Syntax parseReadableSizeOrZero(x) Arguments x β€” Readable size with ISO/IEC 80000-13 or decimal byte unit. String Returned value Returns the number of bytes, rounded up to the nearest integer, or 0 if unable to parse the input. UInt64 Examples Usage example SELECT arrayJoin(['1 B', '1 KiB', '3 MB', '5.314 KiB', 'invalid']) AS readable_sizes, parseReadableSizeOrZero(readable_sizes) AS sizes; β”Œβ”€readable_sizes─┬───sizes─┐ β”‚ 1 B β”‚ 1 β”‚ β”‚ 1 KiB β”‚ 1024 β”‚ β”‚ 3 MB β”‚ 3000000 β”‚ β”‚ 5.314 KiB β”‚ 5442 β”‚ β”‚ invalid β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ parseTimeDelta ​ Introduced in: v22.7.0 Parse a sequence of numbers followed by something resembling a time unit. The time delta string uses these time unit specifications: years , year , yr , y months , month , mo weeks , week , w days , day , d hours , hour , hr , h minutes , minute , min , m seconds , second , sec , s milliseconds , millisecond , millisec , ms microseconds , microsecond , microsec , ΞΌs , Β΅s , us nanoseconds , nanosecond , nanosec , ns Multiple time units can be combined with separators (space, ; , - , + , , , : ). The length of years and months are approximations: year is 365 days, month is 30.5 days. Syntax parseTimeDelta(timestr) Arguments timestr β€” A sequence of numbers followed by something resembling a time unit. String Returned value The number of seconds. Float64 Examples Usage example SELECT parseTimeDelta('11s+22min') β”Œβ”€parseTimeDelta('11s+22min')─┐ β”‚ 1331 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ Complex time units SELECT parseTimeDelta('1yr2mo') β”Œβ”€parseTimeDelta('1yr2mo')─┐ β”‚ 36806400 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ partitionId ​ Introduced in: v21.4.0 Computes the partition ID . Note This function is slow and should not be called for large numbers of rows. Syntax partitionId(column1[, column2, ...]) Aliases : partitionID Arguments column1, column2, ... β€” Column for which to return the partition ID. Returned value Returns the partition ID that the row belongs to. String Examples Usage example DROP TABLE IF EXISTS tab; CREATE TABLE tab ( i int, j int ) ENGINE = MergeTree PARTITION BY i ORDER BY tuple(); INSERT INTO tab VALUES (1, 1), (1, 2), (1, 3), (2, 4), (2, 5), (2, 6); SELECT i, j, partitionId(i), _partition_id FROM tab ORDER BY i, j; β”Œβ”€i─┬─j─┬─partitionId(i)─┬─_partition_id─┐ β”‚ 1 β”‚ 1 β”‚ 1 β”‚ 1 β”‚ β”‚ 1 β”‚ 2 β”‚ 1 β”‚ 1 β”‚ β”‚ 1 β”‚ 3 β”‚ 1 β”‚ 1 β”‚ β”‚ 2 β”‚ 4 β”‚ 2 β”‚ 2 β”‚ β”‚ 2 β”‚ 5 β”‚ 2 β”‚ 2 β”‚ β”‚ 2 β”‚ 6 β”‚ 2 β”‚ 2 β”‚ β””β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ queryID ​ Introduced in: v21.9.0 Returns the ID of the current query. Other parameters of a query can be extracted from field query_id in the system.query_log table. In contrast to initialQueryID function, queryID can return different results on different shards. Syntax queryID() Aliases : query_id Arguments None. Returned value Returns the ID of the current query. String Examples Usage example CREATE TABLE tmp (str String) ENGINE = Log; INSERT INTO tmp (*) VALUES ('a'); SELECT count(DISTINCT t) FROM (SELECT queryID() AS t FROM remote('127.0.0.{1..3}', currentDatabase(), 'tmp') GROUP BY queryID()); β”Œβ”€count(DISTINCT t)─┐ β”‚ 3 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ revision ​ Introduced in: v22.7.0 Returns the current ClickHouse server revision. Syntax revision() Arguments None. Returned value Returns the current ClickHouse server revision. UInt32 Examples Usage example SELECT revision() β”Œβ”€revision()─┐ β”‚ 54485 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ rowNumberInAllBlocks ​ Introduced in: v1.1.0 Returns a unique row number for each row processed. Syntax rowNumberInAllBlocks() Arguments None. Returned value Returns the ordinal number of the row in the data block starting from 0 . UInt64 Examples Usage example SELECT rowNumberInAllBlocks() FROM ( SELECT * FROM system.numbers_mt LIMIT 10 ) SETTINGS max_block_size = 2 β”Œβ”€rowNumberInAllBlocks()─┐ β”‚ 0 β”‚ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€rowNumberInAllBlocks()─┐ β”‚ 4 β”‚ β”‚ 5 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€rowNumberInAllBlocks()─┐ β”‚ 2 β”‚ β”‚ 3 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€rowNumberInAllBlocks()─┐ β”‚ 6 β”‚ β”‚ 7 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€rowNumberInAllBlocks()─┐ β”‚ 8 β”‚ β”‚ 9 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ rowNumberInBlock ​ Introduced in: v1.1.0 For each block processed by rowNumberInBlock , returns the number of the current row. The returned number starts from 0 for each block. Syntax rowNumberInBlock() Arguments None. Returned value Returns the ordinal number of the row in the data block starting from 0 . UInt64 Examples Usage example SELECT rowNumberInBlock() FROM ( SELECT * FROM system.numbers_mt LIMIT 10 ) SETTINGS max_block_size = 2 β”Œβ”€rowNumberInBlock()─┐ β”‚ 0 β”‚ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€rowNumberInBlock()─┐ β”‚ 0 β”‚ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€rowNumberInBlock()─┐ β”‚ 0 β”‚ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€rowNumberInBlock()─┐ β”‚ 0 β”‚ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€rowNumberInBlock()─┐ β”‚ 0 β”‚ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ runningAccumulate ​ Introduced in: v1.1.0 Accumulates the states of an aggregate function for each row of a data block. Syntax runningAccumulate(agg_state[, grouping]) Arguments agg_state β€” State of the aggregate function. AggregateFunction grouping β€” Optional. Grouping key. The state of the function is reset if the grouping value is changed. It can be any of the supported data types for which the equality operator is defined. Any Returned value Returns the accumulated result for each row. Any Examples Usage example with initializeAggregation WITH initializeAggregation('sumState', number) AS one_row_sum_state SELECT number, finalizeAggregation(one_row_sum_state) AS one_row_sum, runningAccumulate(one_row_sum_state) AS cumulative_sum FROM numbers(5); β”Œβ”€number─┬─one_row_sum─┬─cumulative_sum─┐ β”‚ 0 β”‚ 0 β”‚ 0 β”‚ β”‚ 1 β”‚ 1 β”‚ 1 β”‚ β”‚ 2 β”‚ 2 β”‚ 3 β”‚ β”‚ 3 β”‚ 3 β”‚ 6 β”‚ β”‚ 4 β”‚ 4 β”‚ 10 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ runningConcurrency ​ Introduced in: v21.3.0 Calculates the number of concurrent events. Each event has a start time and an end time. The start time is included in the event, while the end time is excluded. Columns with a start time and an end time must be of the same data type. The function calculates the total number of active (concurrent) events for each event start time. Requirements Events must be ordered by the start time in ascending order. If this requirement is violated the function raises an exception. Every data block is processed separately. If events from different data blocks overlap then they can not be processed correctly. Syntax runningConcurrency(start, end) Arguments start β€” A column with the start time of events. Date or DateTime or DateTime64 end β€” A column with the end time of events. Date or DateTime or DateTime64 Returned value Returns the number of concurrent events at each event start time. UInt32 Examples Usage example SELECT start, runningConcurrency(start, end) FROM example_table; β”Œβ”€β”€β”€β”€β”€β”€start─┬─runningConcurrency(start, end)─┐ β”‚ 2025-03-03 β”‚ 1 β”‚ β”‚ 2025-03-06 β”‚ 2 β”‚ β”‚ 2025-03-07 β”‚ 3 β”‚ β”‚ 2025-03-11 β”‚ 2 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ runningDifference ​ Introduced in: v1.1.0 Calculates the difference between two consecutive row values in the data block. Returns 0 for the first row, and for subsequent rows the difference to the previous row. The result of the function depends on the affected data blocks and the order of data in the block. The order of rows during calculation of runningDifference() can differ from the order of rows returned to the user. To prevent that you can create a subquery with ORDER BY and call the function from outside the subquery. Please note that the block size affects the result. The internal state of runningDifference state is reset for each new block. Syntax runningDifference(x) Arguments x β€” Column for which to calculate the running difference. Any Returned value Returns the difference between consecutive values, with 0 for the first row. Examples Usage example SELECT EventID, EventTime, runningDifference(EventTime) AS delta FROM ( SELECT EventID, EventTime FROM events WHERE EventDate = '2025-11-24' ORDER BY EventTime ASC LIMIT 5 ); β”Œβ”€EventID─┬───────────EventTime─┬─delta─┐ β”‚ 1106 β”‚ 2025-11-24 00:00:04 β”‚ 0 β”‚ β”‚ 1107 β”‚ 2025-11-24 00:00:05 β”‚ 1 β”‚ β”‚ 1108 β”‚ 2025-11-24 00:00:05 β”‚ 0 β”‚ β”‚ 1109 β”‚ 2025-11-24 00:00:09 β”‚ 4 β”‚ β”‚ 1110 β”‚ 2025-11-24 00:00:10 β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”˜ Block size impact example SELECT number, runningDifference(number + 1) AS diff FROM numbers(100000) WHERE diff != 1; β”Œβ”€number─┬─diff─┐ β”‚ 0 β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€number─┬─diff─┐ β”‚ 65536 β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”˜ runningDifferenceStartingWithFirstValue ​ Introduced in: v1.1.0 Calculates the difference between consecutive row values in a data block, but unlike runningDifference , it returns the actual value of the first row instead of 0 . Deprecated Only returns differences inside the currently processed data block. Because of this error-prone behavior, the function is deprecated. It is advised to use window functions instead. You can use setting allow_deprecated_error_prone_window_functions to allow usage of this function. Syntax runningDifferenceStartingWithFirstValue(x) Arguments x β€” Column for which to calculate the running difference. Any Returned value Returns the difference between consecutive values, with the first row's value for the first row. Any Examples Usage example SELECT number, runningDifferenceStartingWithFirstValue(number) AS diff FROM numbers(5); β”Œβ”€number─┬─diff─┐ β”‚ 0 β”‚ 0 β”‚ β”‚ 1 β”‚ 1 β”‚ β”‚ 2 β”‚ 1 β”‚ β”‚ 3 β”‚ 1 β”‚ β”‚ 4 β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”˜ serverUUID ​ Introduced in: v20.1.0 Returns the random and unique UUID (v4) generated when the server is first started. The UUID is persisted, i.e. the second, third, etc. server start return the same UUID. Syntax serverUUID() Arguments None. Returned value Returns the random UUID of the server. UUID Examples Usage example SELECT serverUUID(); β”Œβ”€serverUUID()─────────────────────────────┐ β”‚ 7ccc9260-000d-4d5c-a843-5459abaabb5f β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ shardCount ​ Introduced in: v21.9.0 Returns the total number of shards for a distributed query. If a query is not distributed then constant value 0 is returned. Syntax shardCount() Arguments None. Returned value Returns the total number of shards or 0 . UInt32 Examples Usage example -- See shardNum() example above which also demonstrates shardCount() CREATE TABLE shard_count_example (dummy UInt8) ENGINE=Distributed(test_cluster_two_shards_localhost, system, one, dummy); SELECT shardCount() FROM shard_count_example; β”Œβ”€shardCount()─┐ β”‚ 2 β”‚ β”‚ 2 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ shardNum ​ Introduced in: v21.9.0 Returns the index of a shard which processes a part of data in a distributed query. Indices begin from 1 . If a query is not distributed then a constant value 0 is returned. Syntax shardNum() Arguments None. Returned value Returns the shard index or a constant 0 . UInt32 Examples Usage example CREATE TABLE shard_num_example (dummy UInt8) ENGINE=Distributed(test_cluster_two_shards_localhost, system, one, dummy); SELECT dummy, shardNum(), shardCount() FROM shard_num_example; β”Œβ”€dummy─┬─shardNum()─┬─shardCount()─┐ β”‚ 0 β”‚ 1 β”‚ 2 β”‚ β”‚ 0 β”‚ 2 β”‚ 2 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ showCertificate ​ Introduced in: v22.6.0 Shows information about the current server's Secure Sockets Layer (SSL) certificate if it has been configured. See Configuring TLS for more information on how to configure ClickHouse to use OpenSSL certificates to validate connections. Syntax showCertificate() Arguments None. Returned value Returns map of key-value pairs relating to the configured SSL certificate. Map(String, String) Examples Usage example SELECT showCertificate() FORMAT LineAsString; {'version':'1','serial_number':'2D9071D64530052D48308473922C7ADAFA85D6C5','signature_algo':'sha256WithRSAEncryption','issuer':'/CN=marsnet.local CA','not_before':'May 7 17:01:21 2024 GMT','not_after':'May 7 17:01:21 2025 GMT','subject':'/CN=chnode1','pkey_algo':'rsaEncryption'} sleep ​ Introduced in: v1.1.0 Pauses the execution of a query by the specified number of seconds. The function is primarily used for testing and debugging purposes. The sleep() function should generally not be used in production environments, as it can negatively impact query performance and system responsiveness. However, it can be useful in the following scenarios: Testing : When testing or benchmarking ClickHouse, you may want to simulate delays or introduce pauses to observe how the system behaves under certain conditions. Debugging : If you need to examine the state of the system or the execution of a query at a specific point in time, you can use sleep() to introduce a pause, allowing you to inspect or collect relevant information. Simulation : In some cases, you may want to simulate real-world scenarios where delays or pauses occur, such as network latency or external system dependencies. Note It's important to use the sleep() function judiciously and only when necessary, as it can potentially impact the overall performance and responsiveness of your ClickHouse system. For security reasons, the function can only be executed in the default user profile (with allow_sleep enabled). Syntax sleep(seconds) Arguments seconds β€” The number of seconds to pause the query execution to a maximum of 3 seconds. It can be a floating-point value to specify fractional seconds. const UInt* or const Float* Returned value Returns 0 . UInt8 Examples Usage example -- This query will pause for 2 seconds before completing. -- During this time, no results will be returned, and the query will appear to be hanging or unresponsive. SELECT sleep(2); β”Œβ”€sleep(2)─┐ β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ 1 row in set. Elapsed: 2.012 sec. sleepEachRow ​ Introduced in: v1.1.0 Pauses the execution of a query for a specified number of seconds for each row in the result set. The sleepEachRow() function is primarily used for testing and debugging purposes, similar to the sleep() function. It allows you to simulate delays or introduce pauses in the processing of each row, which can be useful in scenarios such as: Testing : When testing or benchmarking ClickHouse's performance under specific conditions, you can use sleepEachRow() to simulate delays or introduce pauses for each row processed. Debugging : If you need to examine the state of the system or the execution of a query for each row processed, you can use sleepEachRow() to introduce pauses, allowing you to inspect or collect relevant information. Simulation : In some cases, you may want to simulate real-world scenarios where delays or pauses occur for each row processed, such as when dealing with external systems or network latencies. Note Like the sleep() function, it's important to use sleepEachRow() judiciously and only when necessary, as it can significantly impact the overall performance and responsiveness of your ClickHouse system, especially when dealing with large result sets. Syntax sleepEachRow(seconds) Arguments seconds β€” The number of seconds to pause the query execution for each row in the result set to a maximum of 3 seconds. It can be a floating-point value to specify fractional seconds. const UInt* or const Float* Returned value Returns 0 for each row. UInt8 Examples Usage example -- The output will be delayed, with a 0.5-second pause between each row. SELECT number, sleepEachRow(0.5) FROM system.numbers LIMIT 5; β”Œβ”€number─┬─sleepEachRow(0.5)─┐ β”‚ 0 β”‚ 0 β”‚ β”‚ 1 β”‚ 0 β”‚ β”‚ 2 β”‚ 0 β”‚ β”‚ 3 β”‚ 0 β”‚ β”‚ 4 β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ structureToCapnProtoSchema ​ Introduced in: v23.8.0 Function that converts ClickHouse table structure to CapnProto format schema Syntax structureToCapnProtoSchema(table_structure, message) Arguments None. Returned value Examples random SELECT structureToCapnProtoSchema('s String, x UInt32', 'MessageName') format TSVRaw struct MessageName { s @0 : Data; x @1 : UInt32; } structureToProtobufSchema ​ Introduced in: v23.8.0 Converts a ClickHouse table structure to Protobuf format schema. This function takes a ClickHouse table structure definition and converts it into a Protocol Buffers (Protobuf) schema definition in proto3 syntax. This is useful for generating Protobuf schemas that match your ClickHouse table structures for data interchange. Syntax structureToProtobufSchema(structure, message_name) Arguments structure β€” ClickHouse table structure definition as a string (e.g., 'column1 Type1, column2 Type2'). String message_name β€” Name for the Protobuf message type in the generated schema. String Returned value Returns a Protobuf schema definition in proto3 syntax that corresponds to the input ClickHouse structure. String Examples Converting ClickHouse structure to Protobuf schema SELECT structureToProtobufSchema('s String, x UInt32', 'MessageName') FORMAT TSVRaw; syntax = "proto3"; message MessageName { bytes s = 1; uint32 x = 2; } tcpPort ​ Introduced in: v20.12.0 Returns the native interface TCP port number listened to by the server. If executed in the context of a distributed table, this function generates a normal column with values relevant to each shard. Otherwise it produces a constant value. Syntax tcpPort() Arguments None. Returned value Returns the TCP port number. UInt16 Examples Usage example SELECT tcpPort() β”Œβ”€tcpPort()─┐ β”‚ 9000 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ throwIf ​ Introduced in: v1.1.0 Throw an exception if argument x is true. To use the error_code argument, configuration parameter allow_custom_error_code_in_throw must be enabled. Syntax throwIf(x[, message[, error_code]]) Arguments x β€” The condition to check. Any message β€” Optional. Custom error message. const String error_code β€” Optional. Custom error code. const Int8/16/32 Returned value Returns 0 if the condition is false, throws an exception if the condition is true. UInt8 Examples Usage example SELECT throwIf(number = 3, 'Too many') FROM numbers(10); ↙ Progress: 0.00 rows, 0.00 B (0.00 rows/s., 0.00 B/s.) Received exception from server (version 19.14.1): Code: 395. DB::Exception: Received from localhost:9000. DB::Exception: Too many. toColumnTypeName ​ Introduced in: v1.1.0 Returns the internal name of the data type of the given value. Unlike function toTypeName , the returned data type potentially includes internal wrapper columns like Const and LowCardinality . Syntax toColumnTypeName(value) Arguments value β€” Value for which to return the internal data type. Any Returned value Returns the internal data type used to represent the value. String Examples Usage example SELECT toColumnTypeName(CAST('2025-01-01 01:02:03' AS DateTime)); β”Œβ”€toColumnTypeName(CAST('2025-01-01 01:02:03', 'DateTime'))─┐ β”‚ Const(UInt32) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ toTypeName ​ Introduced in: v1.1.0 Returns the type name of the passed argument. If NULL is passed, the function returns type Nullable(Nothing) , which corresponds to ClickHouse's internal NULL representation. Syntax toTypeName(x) Arguments x β€” A value of arbitrary type. Any Returned value Returns the data type name of the input value. String Examples Usage example SELECT toTypeName(123) β”Œβ”€toTypeName(123)─┐ β”‚ UInt8 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ transactionID ​ Introduced in: v22.6.0 Not supported in ClickHouse Cloud Returns the ID of a transaction. Note This function is part of an experimental feature set. Enable experimental transaction support by adding this setting to your configuration : <clickhouse> <allow_experimental_transactions>1</allow_experimental_transactions> </clickhouse> For more information see the page Transactional (ACID) support . Syntax transactionID() Arguments None. Returned value Returns a tuple consisting of start_csn , local_tid and host_id . start_csn : Global sequential number, the newest commit timestamp that was seen when this transaction began. local_tid : Local sequential number that is unique for each transaction started by this host within a specific start_csn. host_id : UUID of the host that has started this transaction. Tuple(UInt64, UInt64, UUID) Examples Usage example BEGIN TRANSACTION; SELECT transactionID(); ROLLBACK; β”Œβ”€transactionID()────────────────────────────────┐ β”‚ (32,34,'0ee8b069-f2bb-4748-9eae-069c85b5252b') β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ transactionLatestSnapshot ​ Introduced in: v22.6.0 Not supported in ClickHouse Cloud Returns the newest snapshot (Commit Sequence Number) of a transaction that is available for reading. Note This function is part of an experimental feature set. Enable experimental transaction support by adding this setting to your configuration: <clickhouse> <allow_experimental_transactions>1</allow_experimental_transactions> </clickhouse> For more information see the page Transactional (ACID) support . Syntax transactionLatestSnapshot() Arguments None. Returned value Returns the latest snapshot (CSN) of a transaction. UInt64 Examples Usage example BEGIN TRANSACTION; SELECT transactionLatestSnapshot(); ROLLBACK; β”Œβ”€transactionLatestSnapshot()─┐ β”‚ 32 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ transactionOldestSnapshot ​ Introduced in: v22.6.0 Not supported in ClickHouse Cloud Returns the oldest snapshot (Commit Sequence Number) that is visible for some running transaction . Note This function is part of an experimental feature set. Enable experimental transaction support by adding this setting to your configuration: <clickhouse> <allow_experimental_transactions>1</allow_experimental_transactions> </clickhouse> For more information see the page Transactional (ACID) support . Syntax transactionOldestSnapshot() Arguments None. Returned value Returns the oldest snapshot (CSN) of a transaction. UInt64 Examples Usage example BEGIN TRANSACTION; SELECT transactionOldestSnapshot(); ROLLBACK; β”Œβ”€transactionOldestSnapshot()─┐ β”‚ 32 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ transform ​ Introduced in: v1.1.0 Transforms a value according to the explicitly defined mapping of some elements to other elements. There are two variations of this function: transform(x, array_from, array_to, default) - transforms x using mapping arrays with a default value for unmatched elements transform(x, array_from, array_to) - same transformation but returns the original x if no match is found The function searches for x in array_from and returns the corresponding element from array_to at the same index. If x is not found in array_from , it returns either the default value (4-parameter version) or the original x (3-parameter version). If multiple matching elements exist in array_from , it returns the element corresponding to the first match. Requirements: array_from and array_to must have the same number of elements For 4-parameter version: transform(T, Array(T), Array(U), U) -> U where T and U can be different compatible types For 3-parameter version: transform(T, Array(T), Array(T)) -> T where all types must be the same Syntax transform(x, array_from, array_to[, default]) Arguments x β€” Value to transform. (U)Int* or Decimal or Float* or String or Date or DateTime array_from β€” Constant array of values to search for matches. Array((U)Int*) or Array(Decimal) or Array(Float*) or Array(String) or Array(Date) or Array(DateTime) array_to β€” Constant array of values to return for corresponding matches in array_from . Array((U)Int*) or Array(Decimal) or Array(Float*) or Array(String) or Array(Date) or Array(DateTime) default β€” Optional. Value to return if x is not found in array_from . If omitted, returns x unchanged. (U)Int* or Decimal or Float* or String or Date or DateTime Returned value Returns the corresponding value from array_to if x matches an element in array_from , otherwise returns default (if provided) or x (if default not provided). Any Examples transform(T, Array(T), Array(U), U) -> U SELECT transform(SearchEngineID, [2, 3], ['Yandex', 'Google'], 'Other') AS title, count() AS c FROM test.hits WHERE SearchEngineID != 0 GROUP BY title ORDER BY c DESC β”Œβ”€title─────┬──────c─┐ β”‚ Yandex β”‚ 498635 β”‚ β”‚ Google β”‚ 229872 β”‚ β”‚ Other β”‚ 104472 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜ transform(T, Array(T), Array(T)) -> T SELECT transform(domain(Referer), ['yandex.ru', 'google.ru', 'vkontakte.ru'], ['www.yandex', 'example.com', 'vk.com']) AS s, count() AS c FROM test.hits GROUP BY domain(Referer) ORDER BY count() DESC LIMIT 10 β”Œβ”€s──────────────┬───────c─┐ β”‚ β”‚ 2906259 β”‚ β”‚ www.yandex β”‚ 867767 β”‚ β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ.ru β”‚ 313599 β”‚ β”‚ mail.yandex.ru β”‚ 107147 β”‚ β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ.ru β”‚ 100355 β”‚ β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ.ru β”‚ 65040 β”‚ β”‚ news.yandex.ru β”‚ 64515 β”‚ β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ.net β”‚ 59141 β”‚ β”‚ example.com β”‚ 57316 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ uniqThetaIntersect ​ Introduced in: v22.9.0 Two uniqThetaSketch objects to do intersect calculation(set operation ∩), the result is a new uniqThetaSketch. Syntax uniqThetaIntersect(uniqThetaSketch,uniqThetaSketch) Arguments uniqThetaSketch β€” uniqThetaSketch object. Tuple or Array or Date or DateTime or String or (U)Int* or Float* or Decimal Returned value A new uniqThetaSketch containing the intersect result. UInt64 Examples Usage example SELECT finalizeAggregation(uniqThetaIntersect(a, b)) AS a_intersect_b, finalizeAggregation(a) AS a_cardinality, finalizeAggregation(b) AS b_cardinality FROM (SELECT arrayReduce('uniqThetaState', [1, 2]) AS a, arrayReduce('uniqThetaState', [2, 3, 4]) AS b); β”Œβ”€a_intersect_b─┬─a_cardinality─┬─b_cardinality─┐ β”‚ 1 β”‚ 2 β”‚ 3 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ uniqThetaNot ​ Introduced in: v22.9.0 Two uniqThetaSketch objects to do a_not_b calculation(set operation Γ—), the result is a new uniqThetaSketch. Syntax uniqThetaNot(uniqThetaSketch,uniqThetaSketch) Arguments uniqThetaSketch β€” uniqThetaSketch object. Tuple or Array or Date or DateTime or String or (U)Int* or Float* or Decimal Returned value Returns a new uniqThetaSketch containing the a_not_b result. UInt64 Examples Usage example SELECT finalizeAggregation(uniqThetaNot(a, b)) AS a_not_b, finalizeAggregation(a) AS a_cardinality, finalizeAggregation(b) AS b_cardinality FROM (SELECT arrayReduce('uniqThetaState', [2, 3, 4]) AS a, arrayReduce('uniqThetaState', [1, 2]) AS b); β”Œβ”€a_not_b─┬─a_cardinality─┬─b_cardinality─┐ β”‚ 2 β”‚ 3 β”‚ 2 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ uniqThetaUnion ​ Introduced in: v22.9.0 Two uniqThetaSketch objects to do union calculation(set operation βˆͺ), the result is a new uniqThetaSketch. Syntax uniqThetaUnion(uniqThetaSketch,uniqThetaSketch) Arguments uniqThetaSketch β€” uniqThetaSketch object. Tuple or Array or Date or DateTime or String or (U)Int* or Float* or Decimal Returned value Returns a new uniqThetaSketch containing the union result. UInt64 Examples Usage example SELECT finalizeAggregation(uniqThetaUnion(a, b)) AS a_union_b, finalizeAggregation(a) AS a_cardinality, finalizeAggregation(b) AS b_cardinality FROM (SELECT arrayReduce('uniqThetaState', [1, 2]) AS a, arrayReduce('uniqThetaState', [2, 3, 4]) AS b); β”Œβ”€a_union_b─┬─a_cardinality─┬─b_cardinality─┐ β”‚ 4 β”‚ 2 β”‚ 3 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ uptime ​ Introduced in: v1.1.0 Returns the server's uptime in seconds. If executed in the context of a distributed table, this function generates a normal column with values relevant to each shard. Otherwise it produces a constant value. Syntax uptime() Arguments None. Returned value Returns the server uptime in seconds. UInt32 Examples Usage example SELECT uptime() AS Uptime β”Œβ”€Uptime─┐ β”‚ 55867 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ variantElement ​ Introduced in: v25.2.0 Extracts a column with specified type from a Variant column. Syntax variantElement(variant, type_name[, default_value]) Arguments variant β€” Variant column. Variant type_name β€” The name of the variant type to extract. String default_value β€” The default value that will be used if variant doesn't have variant with specified type. Can be any type. Optional. Any Returned value Returns a column with the specified variant type extracted from the Variant column. Any Examples Usage example CREATE TABLE test (v Variant(UInt64, String, Array(UInt64))) ENGINE = Memory; INSERT INTO test VALUES (NULL), (42), ('Hello, World!'), ([1, 2, 3]); SELECT v, variantElement(v, 'String'), variantElement(v, 'UInt64'), variantElement(v, 'Array(UInt64)') FROM test; β”Œβ”€v─────────────┬─variantElement(v, 'String')─┬─variantElement(v, 'UInt64')─┬─variantElement(v, 'Array(UInt64)')─┐ β”‚ ᴺᡁᴸᴸ β”‚ ᴺᡁᴸᴸ β”‚ ᴺᡁᴸᴸ β”‚ [] β”‚ β”‚ 42 β”‚ ᴺᡁᴸᴸ β”‚ 42 β”‚ [] β”‚ β”‚ Hello, World! β”‚ Hello, World! β”‚ ᴺᡁᴸᴸ β”‚ [] β”‚ β”‚ [1,2,3] β”‚ ᴺᡁᴸᴸ β”‚ ᴺᡁᴸᴸ β”‚ [1,2,3] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ variantType ​ Introduced in: v24.2.0 Returns the variant type name for each row of Variant column. If row contains NULL, it returns 'None' for it. Syntax variantType(variant) Arguments variant β€” Variant column. Variant Returned value Returns an Enum column with variant type name for each row. Enum Examples Usage example CREATE TABLE test (v Variant(UInt64, String, Array(UInt64))) ENGINE = Memory; INSERT INTO test VALUES (NULL), (42), ('Hello, World!'), ([1, 2, 3]); SELECT variantType(v) FROM test; β”Œβ”€variantType(v)─┐ β”‚ None β”‚ β”‚ UInt64 β”‚ β”‚ String β”‚ β”‚ Array(UInt64) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ version ​ Introduced in: v1.1.0 Returns the current version of ClickHouse as a string in the form: major_version.minor_version.patch_version.number_of_commits_since_the_previous_stable_release . If executed in the context of a distributed table, this function generates a normal column with values relevant to each shard. Otherwise, it produces a constant value. Syntax version() Arguments None. Returned value Returns the current version of ClickHouse. String Examples Usage example SELECT version() β”Œβ”€version()─┐ β”‚ 24.2.1.1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ visibleWidth ​ Introduced in: v1.1.0 Calculates the approximate width when outputting values to the console in text format (tab-separated). This function is used by the system to implement Pretty formats. NULL is represented as a string corresponding to NULL in Pretty formats. Syntax visibleWidth(x) Arguments x β€” A value of any data type. Any Returned value Returns the approximate width of the value when displayed in text format. UInt64 Examples Calculate visible width of NULL SELECT visibleWidth(NULL) β”Œβ”€visibleWidth(NULL)─┐ β”‚ 4 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ zookeeperSessionUptime ​ Introduced in: v21.11.0 Returns the uptime of the current ZooKeeper session in seconds. Syntax zookeeperSessionUptime() Arguments None. Returned value Returns the uptime of the current ZooKeeper session in seconds. UInt32 Examples Usage example SELECT zookeeperSessionUptime(); β”Œβ”€zookeeperSessionUptime()─┐ β”‚ 286 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Markdown
[Skip to main content](https://clickhouse.com/docs/sql-reference/functions/other-functions#__docusaurus_skipToContent_fallback) [![ClickHouse](https://clickhouse.com/docs/img/ch_logo_docs.svg)](https://clickhouse.com/) - [Products](https://clickhouse.com/docs/sql-reference/functions/other-functions) - [ClickHouse Cloud Best way to use ClickHouse. Available on AWS, GCP, and Azure.](https://clickhouse.com/cloud) - [BYOC (Bring Your Own Cloud) The fully managed ClickHouse Cloud service, Can be deployed in your AWS account.](https://clickhouse.com/cloud/bring-your-own-cloud) - [ClickHouse Set up a database with open-source ClickHouse. ClickHouse](https://clickhouse.com/clickhouse) - [Discover more than 100 integrations.](https://clickhouse.com/integrations) [Discover more than 100 integrations.](https://clickhouse.com/integrations) - [Use cases](https://clickhouse.com/docs/sql-reference/functions/other-functions) - [Real-time analytics](https://clickhouse.com/use-cases/real-time-analytics) - [Machine Learning & Generative AI](https://clickhouse.com/use-cases/machine-learning-and-data-science) - [Business Intelligence](https://clickhouse.com/use-cases/data-warehousing) - [Logs, Events, Traces](https://clickhouse.com/use-cases/observability) - [All use cases](https://clickhouse.com/use-cases) [All use cases](https://clickhouse.com/use-cases) - [Documentation](https://clickhouse.com/docs) - [Resources](https://clickhouse.com/docs/sql-reference/functions/other-functions) - [User stories](https://clickhouse.com/user-stories) - [Blog](https://clickhouse.com/blog) - [Events](https://clickhouse.com/company/events) - [Learning and certification](https://clickhouse.com/learn) - [Comparison](https://clickhouse.com/docs/sql-reference/functions/other-functions) - [BigQuery](https://clickhouse.com/comparison/bigquery) - [PostgreSQL](https://clickhouse.com/comparison/postgresql) - [Redshift](https://clickhouse.com/comparison/redshift) - [Rockset](https://clickhouse.com/comparison/rockset) - [Snowflake](https://clickhouse.com/comparison/snowflake) - [Video](https://clickhouse.com/videos) - [Demo](https://clickhouse.com/demos) - [Pricing](https://clickhouse.com/pricing) - [Contact](https://clickhouse.com/company/contact?loc=nav) [47\.0k](https://github.com/ClickHouse/ClickHouse?utm_source=clickhouse&utm_medium=website&utm_campaign=website-nav) [Search`Ctrl``K`](https://clickhouse.com/docs/search) [Sign in](https://console.clickhouse.cloud/signIn?loc=docs-nav-signIn-cta&glxid=6adfcdfe-d44a-48bb-a003-4ea1abaf38ea&pagePath=%2Fdocs%2Fsql-reference%2Ffunctions%2Fother-functions&origPath=%2Fdocs%2Fsql-reference%2Ffunctions%2Fother-functions&utm_ga=GA1.1.745291207.1776676661) [Get started](https://console.clickhouse.cloud/signUp?loc=docs-nav-signUp-cta&glxid=6adfcdfe-d44a-48bb-a003-4ea1abaf38ea&pagePath=%2Fdocs%2Fsql-reference%2Ffunctions%2Fother-functions&origPath=%2Fdocs%2Fsql-reference%2Ffunctions%2Fother-functions&utm_ga=GA1.1.745291207.1776676661) [Get started](https://clickhouse.com/docs/introduction-clickhouse) [Cloud](https://clickhouse.com/docs/cloud/overview) [Manage data](https://clickhouse.com/docs/updating-data) [Server admin](https://clickhouse.com/docs/guides/manage-and-deploy-index) [Reference](https://clickhouse.com/docs/sql-reference) [Integrations](https://clickhouse.com/docs/integrations) [ClickStack](https://clickhouse.com/docs/use-cases/observability/clickstack/overview) [chDB](https://clickhouse.com/docs/chdb) [About](https://clickhouse.com/docs/about) [Knowledge Base](https://clickhouse.com/docs/knowledgebase) [English](https://clickhouse.com/docs/sql-reference/functions/other-functions) - [English](https://clickhouse.com/docs/sql-reference/functions/other-functions) - [ζ—₯本θͺž](https://clickhouse.com/docs/jp/sql-reference/functions/other-functions) - [δΈ­ζ–‡](https://clickhouse.com/docs/zh/sql-reference/functions/other-functions) - [Русский](https://clickhouse.com/docs/ru/sql-reference/functions/other-functions) - [ν•œκ΅­μ–΄](https://clickhouse.com/docs/ko/sql-reference/functions/other-functions) [Skip to main content](https://clickhouse.com/docs/sql-reference/functions/other-functions#__docusaurus_skipToContent_fallback) [![ClickHouse](https://clickhouse.com/docs/img/ch_logo_docs.svg)](https://clickhouse.com/) - [Products](https://clickhouse.com/docs/sql-reference/functions/other-functions) - [ClickHouse Cloud Best way to use ClickHouse. Available on AWS, GCP, and Azure.](https://clickhouse.com/cloud) - [BYOC (Bring Your Own Cloud) The fully managed ClickHouse Cloud service, Can be deployed in your AWS account.](https://clickhouse.com/cloud/bring-your-own-cloud) - [ClickHouse Set up a database with open-source ClickHouse. ClickHouse](https://clickhouse.com/clickhouse) - [Discover more than 100 integrations.](https://clickhouse.com/integrations) [Discover more than 100 integrations.](https://clickhouse.com/integrations) - [Use cases](https://clickhouse.com/docs/sql-reference/functions/other-functions) - [Real-time analytics](https://clickhouse.com/use-cases/real-time-analytics) - [Machine Learning & Generative AI](https://clickhouse.com/use-cases/machine-learning-and-data-science) - [Business Intelligence](https://clickhouse.com/use-cases/data-warehousing) - [Logs, Events, Traces](https://clickhouse.com/use-cases/observability) - [All use cases](https://clickhouse.com/use-cases) [All use cases](https://clickhouse.com/use-cases) - [Documentation](https://clickhouse.com/docs) - [Resources](https://clickhouse.com/docs/sql-reference/functions/other-functions) - [User stories](https://clickhouse.com/user-stories) - [Blog](https://clickhouse.com/blog) - [Events](https://clickhouse.com/company/events) - [Learning and certification](https://clickhouse.com/learn) - [Comparison](https://clickhouse.com/docs/sql-reference/functions/other-functions) - [BigQuery](https://clickhouse.com/comparison/bigquery) - [PostgreSQL](https://clickhouse.com/comparison/postgresql) - [Redshift](https://clickhouse.com/comparison/redshift) - [Rockset](https://clickhouse.com/comparison/rockset) - [Snowflake](https://clickhouse.com/comparison/snowflake) - [Video](https://clickhouse.com/videos) - [Demo](https://clickhouse.com/demos) - [Pricing](https://clickhouse.com/pricing) - [Contact](https://clickhouse.com/company/contact?loc=nav) [47\.0k](https://github.com/ClickHouse/ClickHouse?utm_source=clickhouse&utm_medium=website&utm_campaign=website-nav) [Search`Ctrl``K`](https://clickhouse.com/docs/search) [Sign in](https://console.clickhouse.cloud/signIn?loc=docs-nav-signIn-cta&glxid=6adfcdfe-d44a-48bb-a003-4ea1abaf38ea&pagePath=%2Fdocs%2Fsql-reference%2Ffunctions%2Fother-functions&origPath=%2Fdocs%2Fsql-reference%2Ffunctions%2Fother-functions&utm_ga=GA1.1.745291207.1776676661) [Get started](https://console.clickhouse.cloud/signUp?loc=docs-nav-signUp-cta&glxid=6adfcdfe-d44a-48bb-a003-4ea1abaf38ea&pagePath=%2Fdocs%2Fsql-reference%2Ffunctions%2Fother-functions&origPath=%2Fdocs%2Fsql-reference%2Ffunctions%2Fother-functions&utm_ga=GA1.1.745291207.1776676661) [Get started](https://clickhouse.com/docs/introduction-clickhouse) [Cloud](https://clickhouse.com/docs/cloud/overview) [Manage data](https://clickhouse.com/docs/updating-data) [Server admin](https://clickhouse.com/docs/guides/manage-and-deploy-index) [Reference](https://clickhouse.com/docs/sql-reference) [Integrations](https://clickhouse.com/docs/integrations) [ClickStack](https://clickhouse.com/docs/use-cases/observability/clickstack/overview) [chDB](https://clickhouse.com/docs/chdb) [About](https://clickhouse.com/docs/about) [Knowledge Base](https://clickhouse.com/docs/knowledgebase) [English](https://clickhouse.com/docs/sql-reference/functions/other-functions) - [English](https://clickhouse.com/docs/sql-reference/functions/other-functions) - [ζ—₯本θͺž](https://clickhouse.com/docs/jp/sql-reference/functions/other-functions) - [δΈ­ζ–‡](https://clickhouse.com/docs/zh/sql-reference/functions/other-functions) - [Русский](https://clickhouse.com/docs/ru/sql-reference/functions/other-functions) - [ν•œκ΅­μ–΄](https://clickhouse.com/docs/ko/sql-reference/functions/other-functions) [Search`Ctrl``K`](https://clickhouse.com/docs/search) - [Introduction](https://clickhouse.com/docs/sql-reference) - [Syntax](https://clickhouse.com/docs/sql-reference/syntax) - [Input and Output Formats](https://clickhouse.com/docs/sql-reference/formats) - [Data types](https://clickhouse.com/docs/sql-reference/data-types) - [Statements](https://clickhouse.com/docs/sql-reference/statements) - [Operators](https://clickhouse.com/docs/sql-reference/operators) - [Engines](https://clickhouse.com/docs/engines) - [Database Engines](https://clickhouse.com/docs/engines/database-engines) - [Table Engines](https://clickhouse.com/docs/engines/table-engines) - [Functions](https://clickhouse.com/docs/sql-reference/functions) - [Regular functions](https://clickhouse.com/docs/sql-reference/functions/regular-functions) - [Overview](https://clickhouse.com/docs/sql-reference/functions/overview) - [AI](https://clickhouse.com/docs/sql-reference/functions/ai-functions) - [Arithmetic](https://clickhouse.com/docs/sql-reference/functions/arithmetic-functions) - [Arrays](https://clickhouse.com/docs/sql-reference/functions/array-functions) - [arrayJoin](https://clickhouse.com/docs/sql-reference/functions/array-join) - [Bit](https://clickhouse.com/docs/sql-reference/functions/bit-functions) - [Bitmap](https://clickhouse.com/docs/sql-reference/functions/bitmap-functions) - [Comparison](https://clickhouse.com/docs/sql-reference/functions/comparison-functions) - [Conditional](https://clickhouse.com/docs/sql-reference/functions/conditional-functions) - [Dates and time](https://clickhouse.com/docs/sql-reference/functions/date-time-functions) - [Distance](https://clickhouse.com/docs/sql-reference/functions/distance-functions) - [Embedded dictionary](https://clickhouse.com/docs/sql-reference/functions/ym-dict-functions) - [Encoding](https://clickhouse.com/docs/sql-reference/functions/encoding-functions) - [Encryption](https://clickhouse.com/docs/sql-reference/functions/encryption-functions) - [Dictionaries](https://clickhouse.com/docs/sql-reference/functions/ext-dict-functions) - [Files](https://clickhouse.com/docs/sql-reference/functions/files) - [Financial](https://clickhouse.com/docs/sql-reference/functions/financial-functions) - [Nullable](https://clickhouse.com/docs/sql-reference/functions/functions-for-nulls) - [Geometry](https://clickhouse.com/docs/sql-reference/functions/geo) - [Hash](https://clickhouse.com/docs/sql-reference/functions/hash-functions) - [IN Operator](https://clickhouse.com/docs/sql-reference/functions/in-functions) - [Introspection](https://clickhouse.com/docs/sql-reference/functions/introspection) - [IP Addresses](https://clickhouse.com/docs/sql-reference/functions/ip-address-functions) - [JSON](https://clickhouse.com/docs/sql-reference/functions/json-functions) - [Logical](https://clickhouse.com/docs/sql-reference/functions/logical-functions) - [Machine Learning](https://clickhouse.com/docs/sql-reference/functions/machine-learning-functions) - [Mathematical](https://clickhouse.com/docs/sql-reference/functions/math-functions) - [NLP](https://clickhouse.com/docs/sql-reference/functions/nlp-functions) - [NumericIndexedVector](https://clickhouse.com/docs/sql-reference/functions/numeric-indexed-vector-functions) - [Other](https://clickhouse.com/docs/sql-reference/functions/other-functions) - [Random number](https://clickhouse.com/docs/sql-reference/functions/random-functions) - [Rounding](https://clickhouse.com/docs/sql-reference/functions/rounding-functions) - [String splitting](https://clickhouse.com/docs/sql-reference/functions/splitting-merging-functions) - [String](https://clickhouse.com/docs/sql-reference/functions/string-functions) - [String replacement](https://clickhouse.com/docs/sql-reference/functions/string-replace-functions) - [String search](https://clickhouse.com/docs/sql-reference/functions/string-search-functions) - [TimeSeries](https://clickhouse.com/docs/sql-reference/functions/time-series-functions) - [Time window](https://clickhouse.com/docs/sql-reference/functions/time-window-functions) - [Tuples](https://clickhouse.com/docs/sql-reference/functions/tuple-functions) - [Maps](https://clickhouse.com/docs/sql-reference/functions/tuple-map-functions) - [Type conversion](https://clickhouse.com/docs/sql-reference/functions/type-conversion-functions) - [UDF](https://clickhouse.com/docs/sql-reference/functions/udf) - [ULIDs](https://clickhouse.com/docs/sql-reference/functions/ulid-functions) - [uniqTheta](https://clickhouse.com/docs/sql-reference/functions/uniqtheta-functions) - [URLs](https://clickhouse.com/docs/sql-reference/functions/url-functions) - [UUIDs](https://clickhouse.com/docs/sql-reference/functions/uuid-functions) - [WebAssembly UDFs](https://clickhouse.com/docs/sql-reference/functions/wasm_udf) - [Aggregate functions](https://clickhouse.com/docs/sql-reference/aggregate-functions) - [Table functions](https://clickhouse.com/docs/sql-reference/table-functions) - [Window functions](https://clickhouse.com/docs/sql-reference/window-functions) - [Formats](https://clickhouse.com/docs/interfaces/formats) - [Data Lakes](https://clickhouse.com/docs/sql-reference/datalakes) - [Functions](https://clickhouse.com/docs/sql-reference/functions) - [Regular functions](https://clickhouse.com/docs/sql-reference/functions/regular-functions) - Other [Edit this page](https://github.com/ClickHouse/ClickHouse/tree/master/docs/en/sql-reference/functions/other-functions.md) # Other functions Note The function documentation below is generated from the `system.functions` system table. ## FQDN[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#FQDN "Direct link to FQDN") Introduced in: v20.1.0 Returns the fully qualified domain name of the ClickHouse server. **Syntax** ``` FQDN() ``` **Aliases**: `fullHostName` **Arguments** - None. **Returned value** Returns the fully qualified domain name of the ClickHouse server. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** Query ``` SELECT fqdn() ``` Response ``` β”Œβ”€FQDN()──────────────────────────┐ β”‚ clickhouse.us-east-2.internal β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## MACNumToString[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#MACNumToString "Direct link to MACNumToString") Introduced in: v1.1.0 Interprets a [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) number as a MAC address in big endian format. Returns the corresponding MAC address in format `AA:BB:CC:DD:EE:FF` (colon-separated numbers in hexadecimal form) as string. **Syntax** ``` MACNumToString(num) ``` **Arguments** - `num` β€” UInt64 number. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Returned value** Returns a MAC address in format AA:BB:CC:DD:EE:FF. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** Query ``` SELECT MACNumToString(149809441867716) AS mac_address; ``` Response ``` β”Œβ”€mac_address───────┐ β”‚ 88:00:11:22:33:44 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## MACStringToNum[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#MACStringToNum "Direct link to MACStringToNum") Introduced in: v1.1.0 The inverse function of MACNumToString. If the MAC address has an invalid format, it returns 0. **Syntax** ``` MACStringToNum(s) ``` **Arguments** - `s` β€” MAC address string. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns a UInt64 number. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** Query ``` SELECT MACStringToNum('01:02:03:04:05:06') AS mac_numeric; ``` Response ``` 1108152157446 ``` ## MACStringToOUI[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#MACStringToOUI "Direct link to MACStringToOUI") Introduced in: v1.1.0 Given a MAC address in format AA:BB:CC:DD:EE:FF (colon-separated numbers in hexadecimal form), returns the first three octets as a UInt64 number. If the MAC address has an invalid format, it returns 0. **Syntax** ``` MACStringToOUI(s) ``` **Arguments** - `s` β€” MAC address string. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** First three octets as UInt64 number. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** Query ``` SELECT MACStringToOUI('00:50:56:12:34:56') AS oui; ``` Response ``` 20566 ``` ## authenticatedUser[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#authenticatedUser "Direct link to authenticatedUser") Introduced in: v25.11.0 If the session user has been switched using the EXECUTE AS command, this function returns the name of the original user that was used for authentication and creating the session. Alias: authUser() **Syntax** ``` authenticatedUser() ``` **Aliases**: `authUser` **Arguments** - None. **Returned value** The name of the authenticated user. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** Query ``` EXECUTE as u1; SELECT currentUser(), authenticatedUser(); ``` Response ``` β”Œβ”€currentUser()─┬─authenticatedUser()─┐ β”‚ u1 β”‚ default β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## bar[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#bar "Direct link to bar") Introduced in: v1.1.0 Builds a bar chart. Draws a band with width proportional to (x - min) and equal to width characters when x = max. The band is drawn with accuracy to one eighth of a symbol. **Syntax** ``` bar(x, min, max[, width]) ``` **Arguments** - `x` β€” Size to display. [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) or [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) - `min` β€” The minimum value. [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) or [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) - `max` β€” The maximum value. [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) or [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) - `width` β€” Optional. The width of the bar in characters. The default is `80`. [`const (U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`const Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) or [`const Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) **Returned value** Returns a unicode-art bar string. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** Query ``` SELECT toHour(EventTime) AS h, count() AS c, bar(c, 0, 600000, 20) AS bar FROM test.hits GROUP BY h ORDER BY h ASC ``` Response ``` β”Œβ”€β”€h─┬──────c─┬─bar────────────────┐ β”‚ 0 β”‚ 292907 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‹ β”‚ β”‚ 1 β”‚ 180563 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β”‚ β”‚ 2 β”‚ 114861 β”‚ β–ˆβ–ˆβ–ˆβ–‹ β”‚ β”‚ 3 β”‚ 85069 β”‚ β–ˆβ–ˆβ–‹ β”‚ β”‚ 4 β”‚ 68543 β”‚ β–ˆβ–ˆβ–Ž β”‚ β”‚ 5 β”‚ 78116 β”‚ β–ˆβ–ˆβ–Œ β”‚ β”‚ 6 β”‚ 113474 β”‚ β–ˆβ–ˆβ–ˆβ–‹ β”‚ β”‚ 7 β”‚ 170678 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‹ β”‚ β”‚ 8 β”‚ 278380 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Ž β”‚ β”‚ 9 β”‚ 391053 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β”‚ β”‚ 10 β”‚ 457681 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Ž β”‚ β”‚ 11 β”‚ 493667 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ– β”‚ β”‚ 12 β”‚ 509641 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Š β”‚ β”‚ 13 β”‚ 522947 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ– β”‚ β”‚ 14 β”‚ 539954 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Š β”‚ β”‚ 15 β”‚ 528460 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Œ β”‚ β”‚ 16 β”‚ 539201 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Š β”‚ β”‚ 17 β”‚ 523539 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ– β”‚ β”‚ 18 β”‚ 506467 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Š β”‚ β”‚ 19 β”‚ 520915 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Ž β”‚ β”‚ 20 β”‚ 521665 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ– β”‚ β”‚ 21 β”‚ 542078 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β”‚ β”‚ 22 β”‚ 493642 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ– β”‚ β”‚ 23 β”‚ 400397 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Ž β”‚ β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## blockNumber[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#blockNumber "Direct link to blockNumber") Introduced in: v1.1.0 Returns a monotonically increasing sequence number of the [block](https://clickhouse.com/docs/development/architecture#block) containing the row. The returned block number is updated on a best-effort basis, i.e. it may not be fully accurate. **Syntax** ``` blockNumber() ``` **Arguments** - None. **Returned value** Sequence number of the data block where the row is located. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Basic usage** Query ``` SELECT blockNumber() FROM ( SELECT * FROM system.numbers LIMIT 10 ) SETTINGS max_block_size = 2 ``` Response ``` β”Œβ”€blockNumber()─┐ β”‚ 7 β”‚ β”‚ 7 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€blockNumber()─┐ β”‚ 8 β”‚ β”‚ 8 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€blockNumber()─┐ β”‚ 9 β”‚ β”‚ 9 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€blockNumber()─┐ β”‚ 10 β”‚ β”‚ 10 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€blockNumber()─┐ β”‚ 11 β”‚ β”‚ 11 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## blockSerializedSize[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#blockSerializedSize "Direct link to blockSerializedSize") Introduced in: v20.3.0 Returns the uncompressed size in bytes of a block of values on disk. **Syntax** ``` blockSerializedSize(x1[, x2[, ...]]) ``` **Arguments** - `x1[, x2, ...]` β€” Any number of values for which to get the uncompressed size of the block. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns the number of bytes that will be written to disk for a block of values without compression. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** Query ``` SELECT blockSerializedSize(maxState(1)) AS x; ``` Response ``` β”Œβ”€x─┐ β”‚ 2 β”‚ β””β”€β”€β”€β”˜ ``` ## blockSize[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#blockSize "Direct link to blockSize") Introduced in: v1.1.0 In ClickHouse, queries are processed in [blocks](https://clickhouse.com/docs/development/architecture#block) (chunks). This function returns the size (row count) of the block the function is called on. **Syntax** ``` blockSize() ``` **Arguments** - None. **Returned value** Returns the number of rows in the current block. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** Query ``` SELECT blockSize() FROM system.numbers LIMIT 5 ``` Response ``` β”Œβ”€blockSize()─┐ β”‚ 5 β”‚ β”‚ 5 β”‚ β”‚ 5 β”‚ β”‚ 5 β”‚ β”‚ 5 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## buildId[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#buildId "Direct link to buildId") Introduced in: v20.5.0 Returns the build ID generated by a compiler for the running ClickHouse server binary. If executed in the context of a distributed table, this function generates a normal column with values relevant to each shard. Otherwise it produces a constant value. **Syntax** ``` buildId() ``` **Arguments** - None. **Returned value** Returns the build ID. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** Query ``` SELECT buildId() ``` Response ``` β”Œβ”€buildId()────────────────────────────────┐ β”‚ AB668BEF095FAA6BD26537F197AC2AF48A927FB4 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## byteSize[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#byteSize "Direct link to byteSize") Introduced in: v21.1.0 Returns an estimation of the uncompressed byte size of its arguments in memory. For `String` arguments, the function returns the string length + 8 (length). If the function has multiple arguments, the function accumulates their byte sizes. **Syntax** ``` byteSize(arg1[, arg2, ...]) ``` **Arguments** - `arg1[, arg2, ...]` β€” Values of any data type for which to estimate the uncompressed byte size. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns an estimation of the byte size of the arguments in memory. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** Query ``` SELECT byteSize('string') ``` Response ``` β”Œβ”€byteSize('string')─┐ β”‚ 15 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Multiple arguments** Query ``` SELECT byteSize(NULL, 1, 0.3, '') ``` Response ``` β”Œβ”€byteSize(NULL, 1, 0.3, '')─┐ β”‚ 19 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## catboostEvaluate[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#catboostEvaluate "Direct link to catboostEvaluate") Introduced in: v22.9.0 Evaluate an external catboost model. [CatBoost](https://catboost.ai/) is an open-source gradient boosting library developed by Yandex for machine learning. Accepts a path to a catboost model and model arguments (features). **Prerequisites** 1. Build the catboost evaluation library Before evaluating catboost models, the `libcatboostmodel.<so|dylib>` library must be made available. See [CatBoost documentation](https://catboost.ai/docs/concepts/c-plus-plus-api_dynamic-c-pluplus-wrapper.html) how to compile it. Next, specify the path to `libcatboostmodel.<so|dylib>` in the clickhouse configuration: ``` <clickhouse> ... <catboost_lib_path>/path/to/libcatboostmodel.so</catboost_lib_path> ... </clickhouse> ``` For security and isolation reasons, the model evaluation does not run in the server process but in the clickhouse-library-bridge process. At the first execution of `catboostEvaluate()`, the server starts the library bridge process if it is not running already. Both processes communicate using a HTTP interface. By default, port `9012` is used. A different port can be specified as follows - this is useful if port `9012` is already assigned to a different service. ``` <library_bridge> <port>9019</port> </library_bridge> ``` 1. Train a catboost model using libcatboost See [Training and applying models](https://catboost.ai/docs/features/training.html#training) for how to train catboost models from a training data set. **Syntax** ``` catboostEvaluate(path_to_model, feature_1[, feature_2, ..., feature_n]) ``` **Arguments** - `path_to_model` β€” Path to catboost model. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `feature` β€” One or more model features/arguments. [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) **Returned value** Returns the model evaluation result. [`Float64`](https://clickhouse.com/docs/sql-reference/data-types/float) **Examples** **catboostEvaluate** Query ``` SELECT catboostEvaluate('/root/occupy.bin', Temperature, Humidity, Light, CO2, HumidityRatio) AS prediction FROM occupancy LIMIT 1 ``` Response ``` 4.695691092573497 ``` ## colorOKLABToSRGB[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#colorOKLABToSRGB "Direct link to colorOKLABToSRGB") Introduced in: v26.2.0 Converts a color from the OKLab perceptual color space to the sRGB color space. The input color is specified in the OKLab color space. If the input values are outside the typical OKLab ranges, the result is implementation-defined. OKLab uses three components: - L: perceptual lightness (typically in the range \[0..1\]) - a: green-red opponent axis - b: blue-yellow opponent axis The a and b components are theoretically unbounded, but in practice are between -0.4 and 0.4. OKLab is designed to be perceptually uniform while remaining inexpensive to compute. The conversion is intended to be the inverse of colorSRGBToOKLAB and consists of the following stages: 1. Conversion from OKLab to linear sRGB. 2. Conversion from linear sRGB to gamma-encoded sRGB. The optional gamma argument specifies the exponent used when converting from linear sRGB to gamma-encoded RGB values. If not specified, a default gamma value is used for consistency with colorSRGBToOKLAB. For more information about the OKLab color space and its relationship to sRGB, see <https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/color_value/oklab> . **Syntax** ``` colorOKLABToSRGB(tuple [, gamma]) ``` **Arguments** - `tuple` β€” A tuple of three numeric values `L`, `a`, `b`, where `L` is in the range `[0...1]`. [`Tuple(Float64, Float64, Float64)`](https://clickhouse.com/docs/sql-reference/data-types/tuple) - `gamma` β€” Optional. The exponent that is used to transform linear sRGB back to sRGB by applying `(x ^ (1 / gamma)) * 255` for each channel `x`. Defaults to `2.2`. [`Float64`](https://clickhouse.com/docs/sql-reference/data-types/float) **Returned value** Returns a tuple (R, G, B) representing sRGB color values. [`Tuple(Float64, Float64, Float64)`](https://clickhouse.com/docs/sql-reference/data-types/tuple) **Examples** **Convert OKLAB to sRGB (Float)** Query ``` SELECT colorOKLABToSRGB((0.4466, 0.0991, 0.44)) AS rgb; ``` Response ``` β”Œβ”€rgb──────────────────────┐ β”‚ (198.07056923258935,0,0) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Convert OKLAB to sRGB (UInt8)** Query ``` WITH colorOKLABToSRGB((0.7, 0.1, 0.54)) AS t SELECT tuple(toUInt8(t.1), toUInt8(t.2), toUInt8(t.3)) AS RGB; ``` Response ``` β”Œβ”€RGB──────────┐ β”‚ (255,0,0) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## colorOKLCHToSRGB[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#colorOKLCHToSRGB "Direct link to colorOKLCHToSRGB") Introduced in: v25.7.0 Converts a colour from the **OKLCH** perceptual colour space to the familiar **sRGB** colour space. If `L` is outside the range `[0...1]`, `C` is negative, or `H` is outside the range `[0...360]`, the result is implementation-defined. Note **OKLCH** is a cylindrical version of the OKLab colour space. It's three coordinates are `L` (the lightness in the range `[0...1]`), `C` (chroma `>= 0`) and `H` (hue in degrees from `[0...360]`). OKLab/OKLCH is designed to be perceptually uniform while remaining cheap to compute. The conversion is the inverse of [`colorSRGBToOKLCH`](https://clickhouse.com/docs/sql-reference/functions/other-functions#colorSRGBToOKLCH): 1. OKLCH to OKLab. 2. OKLab to Linear sRGB 3. Linear sRGB to sRGB The second argument gamma is used at the last stage. For references of colors in OKLCH space, and how they correspond to sRGB colors please see <https://oklch.com/>. **Syntax** ``` colorOKLCHToSRGB(tuple [, gamma]) ``` **Arguments** - `tuple` β€” A tuple of three numeric values `L`, `C`, `H`, where `L` is in the range `[0...1]`, `C >= 0` and `H` is in the range `[0...360]`. [`Tuple(Float64, Float64, Float64)`](https://clickhouse.com/docs/sql-reference/data-types/tuple) - `gamma` β€” Optional. The exponent that is used to transform linear sRGB back to sRGB by applying `(x ^ (1 / gamma)) * 255` for each channel `x`. Defaults to `2.2`. [`Float64`](https://clickhouse.com/docs/sql-reference/data-types/float) **Returned value** Returns a tuple (R, G, B) representing sRGB color values. [`Tuple(Float64, Float64, Float64)`](https://clickhouse.com/docs/sql-reference/data-types/tuple) **Examples** **Convert OKLCH to sRGB** ``` SELECT colorOKLCHToSRGB((0.6, 0.12, 40)) AS rgb; ``` ``` β”Œβ”€rgb───────────────────────────────────────────────────────┐ β”‚ (186.02058688365264,100.68677189684993,71.67819977081575) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Convert OKLCH to sRGB (UInt8)** ``` WITH colorOKLCHToSRGB((0.6, 0.12, 40)) AS t SELECT tuple(toUInt8(t.1), toUInt8(t.2), toUInt8(t.3)) AS RGB; ``` ``` β”Œβ”€RGB──────────┐ β”‚ (186,100,71) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## colorSRGBToOKLAB[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#colorSRGBToOKLAB "Direct link to colorSRGBToOKLAB") Introduced in: v26.2.0 Converts a colour encoded in the **sRGB** colour space to the perceptually uniform **OKLAB** colour space. If any input channel is outside `[0...255]` or the gamma value is non-positive, the behaviour is implementation-defined. Note **OKLAB** is a perceptually uniform color space. Its three coordinates are `L` (the lightness in the range `[0...1]`), `a (Green-Red axis)` and `b (Blue-Yellow axis)`. OKLab is designed to be perceptually uniform while remaining cheap to compute. The conversion consists of two stages: 1. sRGB to Linear sRGB 2. Linear sRGB to OKLab **Syntax** ``` colorSRGBToOKLAB(tuple[, gamma]) ``` **Arguments** - `tuple` β€” Tuple of three values R, G, B in the range `[0...255]`. [`Tuple(UInt8, UInt8, UInt8)`](https://clickhouse.com/docs/sql-reference/data-types/tuple) - `gamma` β€” Optional. Exponent that is used to linearize sRGB by applying `(x / 255)^gamma` to each channel `x`. Defaults to `2.2`. [`Float64`](https://clickhouse.com/docs/sql-reference/data-types/float) **Returned value** Returns a tuple (L, a, b) representing the OKLAB color space values. [`Tuple(Float64, Float64, Float64)`](https://clickhouse.com/docs/sql-reference/data-types/tuple) **Examples** **Convert sRGB to OKLAB** ``` SELECT colorSRGBToOKLAB((128, 64, 32), 2.2) AS lab; ``` ``` β”Œβ”€lab──────────────────────────────────────────────────────────┐ β”‚ (0.4436238384931984,0.07266246769242975,0.07500108778529994) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## colorSRGBToOKLCH[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#colorSRGBToOKLCH "Direct link to colorSRGBToOKLCH") Introduced in: v25.7.0 Converts a colour encoded in the **sRGB** colour space to the perceptually uniform **OKLCH** colour space. If any input channel is outside `[0...255]` or the gamma value is non-positive, the behaviour is implementation-defined. Note **OKLCH** is a cylindrical version of the OKLab colour space. It's three coordinates are `L` (the lightness in the range `[0...1]`), `C` (chroma `>= 0`) and `H` (the hue in degrees from `[0...360]`). OKLab/OKLCH is designed to be perceptually uniform while remaining cheap to compute. The conversion consists of three stages: 1. sRGB to Linear sRGB 2. Linear sRGB to OKLab 3. OKLab to OKLCH. For references of colors in the OKLCH space, and how they correspond to sRGB colors, please see <https://OKLCH.com/>. **Syntax** ``` colorSRGBToOKLCH(tuple[, gamma]) ``` **Arguments** - `tuple` β€” Tuple of three values R, G, B in the range `[0...255]`. [`Tuple(UInt8, UInt8, UInt8)`](https://clickhouse.com/docs/sql-reference/data-types/tuple) - `gamma` β€” Optional. Exponent that is used to linearize sRGB by applying `(x / 255)^gamma` to each channel `x`. Defaults to `2.2`. [`Float64`](https://clickhouse.com/docs/sql-reference/data-types/float) **Returned value** Returns a tuple (L, C, H) representing the OKLCH color space values. [`Tuple(Float64, Float64, Float64)`](https://clickhouse.com/docs/sql-reference/data-types/tuple) **Examples** **Convert sRGB to OKLCH** ``` SELECT colorSRGBToOKLCH((128, 64, 32), 2.2) AS lch; ``` ``` β”Œβ”€lch───────────────────────────────────────────────────────┐ β”‚ (0.4436238384931984,0.1044269954567863,45.90734548193018) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## connectionId[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#connectionId "Direct link to connectionId") Introduced in: v21.3.0 Returns the connection ID of the client that submitted the current query. This function is most useful in debugging scenarios. It was created for compatibility with MySQL's `CONNECTION_ID` function. It is not typically used in production queries. **Syntax** ``` connectionId() ``` **Arguments** - None. **Returned value** Returns the connection ID of the current client. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT connectionId(); ``` ``` β”Œβ”€connectionId()─┐ β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## countDigits[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#countDigits "Direct link to countDigits") Introduced in: v20.8.0 Returns the number of decimal digits needed to represent a value. Note This function takes into account the scales of decimal values i.e., it calculates the result over the underlying integer type which is `(value * scale)`. For example: - `countDigits(42) = 2` - `countDigits(42.000) = 5` - `countDigits(0.04200) = 4` Tip You can check decimal overflow for `Decimal64` with `countDigits(x) > 18`, although it is slower than [`isDecimalOverflow`](https://clickhouse.com/docs/sql-reference/functions/other-functions#isDecimalOverflow). **Syntax** ``` countDigits(x) ``` **Arguments** - `x` β€” An integer or decimal value. [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) **Returned value** Returns the number of digits needed to represent `x`. [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT countDigits(toDecimal32(1, 9)), countDigits(toDecimal32(-1, 9)), countDigits(toDecimal64(1, 18)), countDigits(toDecimal64(-1, 18)), countDigits(toDecimal128(1, 38)), countDigits(toDecimal128(-1, 38)); ``` ``` β”Œβ”€countDigits(toDecimal32(1, 9))─┬─countDigits(toDecimal32(-1, 9))─┬─countDigits(toDecimal64(1, 18))─┬─countDigits(toDecimal64(-1, 18))─┬─countDigits(toDecimal128(1, 38))─┬─countDigits(toDecimal128(-1, 38))─┐ β”‚ 10 β”‚ 10 β”‚ 19 β”‚ 19 β”‚ 39 β”‚ 39 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## currentDatabase[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#currentDatabase "Direct link to currentDatabase") Introduced in: v1.1.0 Returns the name of the current database. Useful in table engine parameters of `CREATE TABLE` queries where you need to specify the database. Also see the [`SET` statement](https://clickhouse.com/docs/sql-reference/statements/use). **Syntax** ``` currentDatabase() ``` **Aliases**: `current_database`, `SCHEMA`, `DATABASE` **Arguments** - None. **Returned value** Returns the current database name. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT currentDatabase() ``` ``` β”Œβ”€currentDatabase()─┐ β”‚ default β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **SQL standard syntax without parentheses** ``` SELECT CURRENT_DATABASE ``` ``` β”Œβ”€CURRENT_DATABASE─┐ β”‚ default β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## currentProfiles[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#currentProfiles "Direct link to currentProfiles") Introduced in: v21.9.0 Returns an array of the setting profiles for the current user. **Syntax** ``` currentProfiles() ``` **Arguments** - None. **Returned value** Returns an array of setting profiles for the current user. [`Array(String)`](https://clickhouse.com/docs/sql-reference/data-types/array) **Examples** **Usage example** ``` SELECT currentProfiles(); ``` ``` β”Œβ”€currentProfiles()─────────────────────────────┐ β”‚ ['default', 'readonly_user', 'web_analytics'] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## currentQueryID[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#currentQueryID "Direct link to currentQueryID") Introduced in: v25.2.0 Returns current Query id. **Syntax** ``` currentQueryID() ``` **Aliases**: `current_query_id` **Arguments** - None. **Returned value** **Examples** **Example** ``` SELECT currentQueryID(); ``` ``` β”Œβ”€currentQueryID()─────────────────────┐ β”‚ 1280d0e8-1a08-4524-be6e-77975bb68e7d β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## currentRoles[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#currentRoles "Direct link to currentRoles") Introduced in: v21.9.0 Returns an array of the roles which are assigned to the current user. **Syntax** ``` currentRoles() ``` **Arguments** - None. **Returned value** Returns an array of the roles which are assigned to the current user. [`Array(String)`](https://clickhouse.com/docs/sql-reference/data-types/array) **Examples** **Usage example** ``` SELECT currentRoles(); ``` ``` β”Œβ”€currentRoles()─────────────────────────────────┐ β”‚ ['sql-console-role:jane.smith@clickhouse.com'] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## currentSchemas[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#currentSchemas "Direct link to currentSchemas") Introduced in: v23.7.0 Same as function [`currentDatabase`](https://clickhouse.com/docs/sql-reference/functions/other-functions#currentDatabase) but - accepts a boolean argument which is ignored - returns the database name as an array with a single value. Function `currentSchemas` only exists for compatibility with PostgreSQL. Please use `currentDatabase` instead. Also see the [`SET` statement](https://clickhouse.com/docs/sql-reference/statements/use). **Syntax** ``` currentSchemas(bool) ``` **Aliases**: `current_schemas` **Arguments** - `bool` β€” A boolean value, which is ignored. [`Bool`](https://clickhouse.com/docs/sql-reference/data-types/boolean) **Returned value** Returns a single-element array with the name of the current database. [`Array(String)`](https://clickhouse.com/docs/sql-reference/data-types/array) **Examples** **Usage example** ``` SELECT currentSchemas(true) ``` ``` β”Œβ”€currentSchemas(true)─┐ β”‚ ['default'] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## currentUser[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#currentUser "Direct link to currentUser") Introduced in: v20.1.0 Returns the name of the current user. In case of a distributed query, the name of the user who initiated the query is returned. **Syntax** ``` currentUser() ``` **Aliases**: `current_user`, `user` **Arguments** - None. **Returned value** Returns the name of the current user, otherwise the login of the user who initiated the query. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT currentUser() ``` ``` β”Œβ”€currentUser()─┐ β”‚ default β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **SQL standard syntax without parentheses** ``` SELECT CURRENT_USER ``` ``` β”Œβ”€CURRENT_USER─┐ β”‚ default β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## defaultProfiles[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#defaultProfiles "Direct link to defaultProfiles") Introduced in: v21.9.0 Returns an array of default setting profile names for the current user. **Syntax** ``` defaultProfiles() ``` **Arguments** - None. **Returned value** Returns an array of default setting profile names for the current user. [`Array(String)`](https://clickhouse.com/docs/sql-reference/data-types/array) **Examples** **Usage example** ``` SELECT defaultProfiles(); ``` ``` β”Œβ”€defaultProfiles()─┐ β”‚ ['default'] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## defaultRoles[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#defaultRoles "Direct link to defaultRoles") Introduced in: v21.9.0 Returns an array of default roles for the current user. **Syntax** ``` defaultRoles() ``` **Arguments** - None. **Returned value** Returns an array of default roles for the current user. [`Array(String)`](https://clickhouse.com/docs/sql-reference/data-types/array) **Examples** **Usage example** ``` SELECT defaultRoles(); ``` ``` β”Œβ”€defaultRoles()─────────────────────────────────┐ β”‚ ['sql-console-role:jane.smith@clickhouse.com'] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## defaultValueOfArgumentType[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#defaultValueOfArgumentType "Direct link to defaultValueOfArgumentType") Introduced in: v1.1.0 Returns the default value for a given data type. Does not include default values for custom columns set by the user. **Syntax** ``` defaultValueOfArgumentType(expression) ``` **Arguments** - `expression` β€” Arbitrary type of value or an expression that results in a value of an arbitrary type. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns `0` for numbers, an empty string for strings or `NULL` for Nullable types. [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`NULL`](https://clickhouse.com/docs/sql-reference/syntax#null) **Examples** **Usage example** ``` SELECT defaultValueOfArgumentType(CAST(1 AS Int8)); ``` ``` β”Œβ”€defaultValueOfArgumentType(CAST(1, 'Int8'))─┐ β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Nullable example** ``` SELECT defaultValueOfArgumentType(CAST(1 AS Nullable(Int8))); ``` ``` β”Œβ”€defaultValueOfArgumentType(CAST(1, 'Nullable(Int8)'))─┐ β”‚ ᴺᡁᴸᴸ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## defaultValueOfTypeName[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#defaultValueOfTypeName "Direct link to defaultValueOfTypeName") Introduced in: v1.1.0 Returns the default value for the given type name. **Syntax** ``` defaultValueOfTypeName(type) ``` **Arguments** - `type` β€” A string representing a type name. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the default value for the given type name: `0` for numbers, an empty string for strings, or `NULL` for Nullable [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`NULL`](https://clickhouse.com/docs/sql-reference/syntax#null) **Examples** **Usage example** ``` SELECT defaultValueOfTypeName('Int8'); ``` ``` β”Œβ”€defaultValueOfTypeName('Int8')─┐ β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Nullable example** ``` SELECT defaultValueOfTypeName('Nullable(Int8)'); ``` ``` β”Œβ”€defaultValueOfTypeName('Nullable(Int8)')─┐ β”‚ ᴺᡁᴸᴸ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## displayName[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#displayName "Direct link to displayName") Introduced in: v22.11.0 Returns the value of `display_name` from [config](https://clickhouse.com/docs/operations/configuration-files) or the server's Fully Qualified Domain Name (FQDN) if not set. **Syntax** ``` displayName() ``` **Arguments** - None. **Returned value** Returns the value of `display_name` from config or server FQDN if not set. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT displayName(); ``` ``` β”Œβ”€displayName()─┐ β”‚ production β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## dumpColumnStructure[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#dumpColumnStructure "Direct link to dumpColumnStructure") Introduced in: v1.1.0 Outputs a detailed description of the internal structure of a column and its data type. **Syntax** ``` dumpColumnStructure(x) ``` **Arguments** - `x` β€” Value for which to get the description of. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns a description of the column structure used for representing the value. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT dumpColumnStructure(CAST('2018-01-01 01:02:03', 'DateTime')); ``` ``` β”Œβ”€dumpColumnStructure(CAST('2018-01-01 01:02:03', 'DateTime'))─┐ β”‚ DateTime, Const(size = 1, UInt32(size = 1)) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## enabledProfiles[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#enabledProfiles "Direct link to enabledProfiles") Introduced in: v21.9.0 Returns an array of setting profile names which are enabled for the current user. **Syntax** ``` enabledProfiles() ``` **Arguments** - None. **Returned value** Returns an array of setting profile names which are enabled for the current user. [`Array(String)`](https://clickhouse.com/docs/sql-reference/data-types/array) **Examples** **Usage example** ``` SELECT enabledProfiles(); ``` ``` β”Œβ”€enabledProfiles()─────────────────────────────────────────────────┐ β”‚ ['default', 'readonly_user', 'web_analytics', 'batch_processing'] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## enabledRoles[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#enabledRoles "Direct link to enabledRoles") Introduced in: v21.9.0 Returns an array of the roles which are enabled for the current user. **Syntax** ``` enabledRoles() ``` **Arguments** - None. **Returned value** Returns an array of role names which are enabled for the current user. [`Array(String)`](https://clickhouse.com/docs/sql-reference/data-types/array) **Examples** **Usage example** ``` SELECT enabledRoles(); ``` ``` β”Œβ”€enabledRoles()─────────────────────────────────────────────────┐ β”‚ ['general_data', 'sql-console-role:jane.smith@clickhouse.com'] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## errorCodeToName[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#errorCodeToName "Direct link to errorCodeToName") Introduced in: v20.12.0 Returns the textual name of a numeric ClickHouse error code. The mapping from numeric error codes to error names is available [here](https://github.com/ClickHouse/ClickHouse/blob/master/src/Common/ErrorCodes.cpp). **Syntax** ``` errorCodeToName(error_code) ``` **Arguments** - `error_code` β€” ClickHouse error code. [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) or [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) **Returned value** Returns the textual name of `error_code`. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT errorCodeToName(252); ``` ``` β”Œβ”€errorCodeToName(252)─┐ β”‚ TOO_MANY_PARTS β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## file[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#file "Direct link to file") Introduced in: v21.3.0 Reads a file as a string and loads the data into the specified column. The file content is not interpreted. Also see the [`file`](https://clickhouse.com/docs/sql-reference/table-functions/file) table function. **Syntax** ``` file(path[, default]) ``` **Arguments** - `path` β€” The path of the file relative to the `user_files_path`. Supports wildcards `*`, `**`, `?`, `{abc,def}` and `{N..M}` where `N`, `M` are numbers and `'abc', 'def'` are strings. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `default` β€” The value returned if the file does not exist or cannot be accessed. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`NULL`](https://clickhouse.com/docs/sql-reference/syntax#null) **Returned value** Returns the file content as a string. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Insert files into a table** ``` INSERT INTO table SELECT file('a.txt'), file('b.txt'); ``` ``` ``` ## filesystemAvailable[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#filesystemAvailable "Direct link to filesystemAvailable") Introduced in: v20.1.0 Returns the amount of free space in the filesystem hosting the database persistence. The returned value is always smaller than the total free space ([`filesystemUnreserved`](https://clickhouse.com/docs/sql-reference/functions/other-functions#filesystemUnreserved)) because some space is reserved for the operating system. **Syntax** ``` filesystemAvailable([disk_name]) ``` **Arguments** - `disk_name` β€” Optional. The disk name to find the amount of free space for. If omitted, uses the default disk. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`FixedString`](https://clickhouse.com/docs/sql-reference/data-types/fixedstring) **Returned value** Returns the amount of remaining space available in bytes. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT formatReadableSize(filesystemAvailable()) AS "Available space"; ``` ``` β”Œβ”€Available space─┐ β”‚ 30.75 GiB β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## filesystemCapacity[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#filesystemCapacity "Direct link to filesystemCapacity") Introduced in: v20.1.0 Returns the capacity of the filesystem in bytes. Needs the [path](https://clickhouse.com/docs/operations/server-configuration-parameters/settings#path) to the data directory to be configured. **Syntax** ``` filesystemCapacity([disk_name]) ``` **Arguments** - `disk_name` β€” Optional. The disk name to get the capacity for. If omitted, uses the default disk. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`FixedString`](https://clickhouse.com/docs/sql-reference/data-types/fixedstring) **Returned value** Returns the capacity of the filesystem in bytes. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT formatReadableSize(filesystemCapacity()) AS "Capacity"; ``` ``` β”Œβ”€Capacity──┐ β”‚ 39.32 GiB β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## filesystemUnreserved[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#filesystemUnreserved "Direct link to filesystemUnreserved") Introduced in: v22.12.0 Returns the total amount of free space on the filesystem hosting the database persistence (previously `filesystemFree`). See also [`filesystemAvailable`](https://clickhouse.com/docs/sql-reference/functions/other-functions#filesystemAvailable). **Syntax** ``` filesystemUnreserved([disk_name]) ``` **Arguments** - `disk_name` β€” Optional. The disk name for which to find the total amount of free space. If omitted, uses the default disk. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`FixedString`](https://clickhouse.com/docs/sql-reference/data-types/fixedstring) **Returned value** Returns the amount of free space in bytes. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT formatReadableSize(filesystemUnreserved()) AS "Free space"; ``` ``` β”Œβ”€Free space─┐ β”‚ 32.39 GiB β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## finalizeAggregation[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#finalizeAggregation "Direct link to finalizeAggregation") Introduced in: v1.1.0 Given an aggregation state, this function returns the result of aggregation (or the finalized state when using a [\-State](https://clickhouse.com/docs/sql-reference/aggregate-functions/combinators#-state) combinator). **Syntax** ``` finalizeAggregation(state) ``` **Arguments** - `state` β€” State of aggregation. [`AggregateFunction`](https://clickhouse.com/docs/sql-reference/data-types/aggregatefunction) **Returned value** Returns the finalized result of aggregation. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **Usage example** ``` SELECT finalizeAggregation(arrayReduce('maxState', [1, 2, 3])); ``` ``` β”Œβ”€finalizeAggregation(arrayReduce('maxState', [1, 2, 3]))─┐ β”‚ 3 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Combined with initializeAggregation** ``` WITH initializeAggregation('sumState', number) AS one_row_sum_state SELECT number, finalizeAggregation(one_row_sum_state) AS one_row_sum, runningAccumulate(one_row_sum_state) AS cumulative_sum FROM numbers(5); ``` ``` β”Œβ”€number─┬─one_row_sum─┬─cumulative_sum─┐ β”‚ 0 β”‚ 0 β”‚ 0 β”‚ β”‚ 1 β”‚ 1 β”‚ 1 β”‚ β”‚ 2 β”‚ 2 β”‚ 3 β”‚ β”‚ 3 β”‚ 3 β”‚ 6 β”‚ β”‚ 4 β”‚ 4 β”‚ 10 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## flipCoordinates[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#flipCoordinates "Direct link to flipCoordinates") Introduced in: v25.10.0 Flips the x and y coordinates of geometric objects. This operation swaps latitude and longitude, which is useful for converting between different coordinate systems or correcting coordinate order. For a Point, it swaps the x and y coordinates. For complex geometries (LineString, Polygon, MultiPolygon, Ring, MultiLineString), it recursively applies the transformation to each coordinate pair. The function supports both individual geometry types (Point, Ring, Polygon, MultiPolygon, LineString, MultiLineString) and the Geometry variant type. **Syntax** ``` flipCoordinates(geometry) ``` **Arguments** - `geometry` β€” The geometry to transform. Supported types: Point (Tuple(Float64, Float64)), Ring (Array(Point)), Polygon (Array(Ring)), MultiPolygon (Array(Polygon)), LineString (Array(Point)), MultiLineString (Array(LineString)), or Geometry (a variant containing any of these types). **Returned value** The geometry with flipped coordinates. The return type matches the input type. [`Point`](https://clickhouse.com/docs/sql-reference/data-types/geo#point) or [`Ring`](https://clickhouse.com/docs/sql-reference/data-types/geo#ring) or [`Polygon`](https://clickhouse.com/docs/sql-reference/data-types/geo#polygon) or [`MultiPolygon`](https://clickhouse.com/docs/sql-reference/data-types/geo#multipolygon) or [`LineString`](https://clickhouse.com/docs/sql-reference/data-types/geo#linestring) or [`MultiLineString`](https://clickhouse.com/docs/sql-reference/data-types/geo#multilinestring) or [`Geometry`](https://clickhouse.com/docs/sql-reference/data-types/geo) **Examples** **basic\_point** ``` SELECT flipCoordinates((1.0, 2.0)); ``` ``` (2.0, 1.0) ``` **ring** ``` SELECT flipCoordinates([(1.0, 2.0), (3.0, 4.0)]); ``` ``` [(2.0, 1.0), (4.0, 3.0)] ``` **polygon** ``` SELECT flipCoordinates([[(1.0, 2.0), (3.0, 4.0)], [(5.0, 6.0), (7.0, 8.0)]]); ``` ``` [[(2.0, 1.0), (4.0, 3.0)], [(6.0, 5.0), (8.0, 7.0)]] ``` **geometry\_wkt** ``` SELECT flipCoordinates(readWkt('POINT(10 20)')); ``` ``` (20, 10) ``` **geometry\_polygon\_wkt** ``` SELECT flipCoordinates(readWkt('POLYGON((0 0, 5 0, 5 5, 0 5, 0 0))')); ``` ``` [[(0, 0), (0, 5), (5, 5), (5, 0), (0, 0)]] ``` ## formatQuery[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatQuery "Direct link to formatQuery") Introduced in: v23.10.0 Returns a formatted, possibly multi-line, version of the given SQL query. Throws in case of a parsing error. \[example:multiline\] **Syntax** ``` formatQuery(query) ``` **Arguments** - `query` β€” The SQL query to be formatted. [String](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** The formatted query [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **multiline** ``` SELECT formatQuery('select a, b FRom tab WHERE a > 3 and b < 3'); ``` ``` SELECT a, b FROM tab WHERE (a > 3) AND (b < 3) ``` ## formatQueryOrNull[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatQueryOrNull "Direct link to formatQueryOrNull") Introduced in: v23.11.0 Returns a formatted, possibly multi-line, version of the given SQL query. Returns NULL in case of a parsing error. \[example:multiline\] **Syntax** ``` formatQueryOrNull(query) ``` **Arguments** - `query` β€” The SQL query to be formatted. [String](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** The formatted query [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **multiline** ``` SELECT formatQuery('select a, b FRom tab WHERE a > 3 and b < 3'); ``` ``` SELECT a, b FROM tab WHERE (a > 3) AND (b < 3) ``` ## formatQuerySingleLine[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatQuerySingleLine "Direct link to formatQuerySingleLine") Introduced in: v23.10.0 Like formatQuery() but the returned formatted string contains no line breaks. Throws in case of a parsing error. \[example:multiline\] **Syntax** ``` formatQuerySingleLine(query) ``` **Arguments** - `query` β€” The SQL query to be formatted. [String](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** The formatted query [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **multiline** ``` SELECT formatQuerySingleLine('select a, b FRom tab WHERE a > 3 and b < 3'); ``` ``` SELECT a, b FROM tab WHERE (a > 3) AND (b < 3) ``` ## formatQuerySingleLineOrNull[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatQuerySingleLineOrNull "Direct link to formatQuerySingleLineOrNull") Introduced in: v23.11.0 Like formatQuery() but the returned formatted string contains no line breaks. Returns NULL in case of a parsing error. \[example:multiline\] **Syntax** ``` formatQuerySingleLineOrNull(query) ``` **Arguments** - `query` β€” The SQL query to be formatted. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** The formatted query [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **multiline** ``` SELECT formatQuerySingleLine('select a, b FRom tab WHERE a > 3 and b < 3'); ``` ``` SELECT a, b FROM tab WHERE (a > 3) AND (b < 3) ``` ## formatReadableDecimalSize[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatReadableDecimalSize "Direct link to formatReadableDecimalSize") Introduced in: v22.11.0 Given a size (number of bytes), this function returns a readable, rounded size with suffix (KB, MB, etc.) as a string. The opposite operations of this function are [`parseReadableSize`](https://clickhouse.com/docs/sql-reference/functions/other-functions#parseReadableSize). **Syntax** ``` formatReadableDecimalSize(x) ``` **Arguments** - `x` β€” Size in bytes. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Returned value** Returns a readable, rounded size with suffix as a string. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Format file sizes** ``` SELECT arrayJoin([1, 1024, 1024*1024, 192851925]) AS filesize_bytes, formatReadableDecimalSize(filesize_bytes) AS filesize ``` ``` β”Œβ”€filesize_bytes─┬─filesize───┐ β”‚ 1 β”‚ 1.00 B β”‚ β”‚ 1024 β”‚ 1.02 KB β”‚ β”‚ 1048576 β”‚ 1.05 MB β”‚ β”‚ 192851925 β”‚ 192.85 MB β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## formatReadableQuantity[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatReadableQuantity "Direct link to formatReadableQuantity") Introduced in: v20.10.0 Given a number, this function returns a rounded number with suffix (thousand, million, billion, etc.) as a string. This function accepts any numeric type as input, but internally it casts them to `Float64`. Results might be suboptimal with large values. **Syntax** ``` formatReadableQuantity(x) ``` **Arguments** - `x` β€” A number to format. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Returned value** Returns a rounded number with suffix as a string. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Format numbers with suffixes** ``` SELECT arrayJoin([1024, 1234 * 1000, (4567 * 1000) * 1000, 98765432101234]) AS number, formatReadableQuantity(number) AS number_for_humans ``` ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€number─┬─number_for_humans─┐ β”‚ 1024 β”‚ 1.02 thousand β”‚ β”‚ 1234000 β”‚ 1.23 million β”‚ β”‚ 4567000000 β”‚ 4.57 billion β”‚ β”‚ 98765432101234 β”‚ 98.77 trillion β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## formatReadableSize[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatReadableSize "Direct link to formatReadableSize") Introduced in: v1.1.0 Given a size (number of bytes), this function returns a readable, rounded size with suffix (KiB, MiB, etc.) as string. The opposite operations of this function are [`parseReadableSize`](https://clickhouse.com/docs/sql-reference/functions/other-functions#parseReadableSize), [`parseReadableSizeOrZero`](https://clickhouse.com/docs/sql-reference/functions/other-functions#parseReadableSizeOrZero), and [`parseReadableSizeOrNull`](https://clickhouse.com/docs/sql-reference/functions/other-functions#parseReadableSizeOrNull). This function accepts any numeric type as input, but internally it casts them to `Float64`. Results might be suboptimal with large values. **Syntax** ``` formatReadableSize(x) ``` **Aliases**: `FORMAT_BYTES` **Arguments** - `x` β€” Size in bytes. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Returned value** Returns a readable, rounded size with suffix as a string. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Format file sizes** ``` SELECT arrayJoin([1, 1024, 1024*1024, 192851925]) AS filesize_bytes, formatReadableSize(filesize_bytes) AS filesize ``` ``` β”Œβ”€filesize_bytes─┬─filesize───┐ β”‚ 1 β”‚ 1.00 B β”‚ β”‚ 1024 β”‚ 1.00 KiB β”‚ β”‚ 1048576 β”‚ 1.00 MiB β”‚ β”‚ 192851925 β”‚ 183.92 MiB β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## formatReadableTimeDelta[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatReadableTimeDelta "Direct link to formatReadableTimeDelta") Introduced in: v20.12.0 Given a time interval (delta) in seconds, this function returns a time delta with year/month/day/hour/minute/second/millisecond/microsecond/nanosecond as a string. This function accepts any numeric type as input, but internally it casts them to `Float64`. Results might be suboptimal with large values. **Syntax** ``` formatReadableTimeDelta(column[, maximum_unit, minimum_unit]) ``` **Arguments** - `column` β€” A column with a numeric time delta. [`Float64`](https://clickhouse.com/docs/sql-reference/data-types/float) - `maximum_unit` β€” Optional. Maximum unit to show. Acceptable values: `nanoseconds`, `microseconds`, `milliseconds`, `seconds`, `minutes`, `hours`, `days`, `months`, `years`. Default value: `years`. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `minimum_unit` β€” Optional. Minimum unit to show. All smaller units are truncated. Acceptable values: `nanoseconds`, `microseconds`, `milliseconds`, `seconds`, `minutes`, `hours`, `days`, `months`, `years`. If explicitly specified value is bigger than `maximum_unit`, an exception will be thrown. Default value: `seconds` if `maximum_unit` is `seconds` or bigger, `nanoseconds` otherwise. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns a time delta as a string. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT arrayJoin([100, 12345, 432546534]) AS elapsed, formatReadableTimeDelta(elapsed) AS time_delta ``` ``` β”Œβ”€β”€β”€β”€elapsed─┬─time_delta─────────────────────────────────────────────────────┐ β”‚ 100 β”‚ 1 minute and 40 seconds β”‚ β”‚ 12345 β”‚ 3 hours, 25 minutes and 45 seconds β”‚ β”‚ 432546534 β”‚ 13 years, 8 months, 17 days, 7 hours, 48 minutes and 54 secondsβ”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **With maximum unit** ``` SELECT arrayJoin([100, 12345, 432546534]) AS elapsed, formatReadableTimeDelta(elapsed, 'minutes') AS time_delta ``` ``` β”Œβ”€β”€β”€β”€elapsed─┬─time_delta─────────────────────────────────────────────────────┐ β”‚ 100 β”‚ 1 minute and 40 seconds β”‚ β”‚ 12345 β”‚ 205 minutes and 45 seconds β”‚ β”‚ 432546534 β”‚ 7209108 minutes and 54 seconds β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## fuzzQuery[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#fuzzQuery "Direct link to fuzzQuery") Introduced in: v26.2.0 Parses the given query string and applies random AST mutations (fuzzing) to it. Returns the fuzzed query as a string. Non-deterministic: each call may produce a different result. Requires `allow_fuzz_query_functions = 1`. **Syntax** ``` fuzzQuery(query) ``` **Arguments** - `query` β€” The SQL query to be fuzzed. [String](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** The fuzzed query string [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **basic** ``` SET allow_fuzz_query_functions = 1; SELECT fuzzQuery('SELECT 1'); ``` ``` ``` ## generateRandomStructure[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#generateRandomStructure "Direct link to generateRandomStructure") Introduced in: v23.5.0 Generates random table structure in the format `column1_name column1_type, column2_name column2_type, ...`. **Syntax** ``` generateRandomStructure([number_of_columns, seed]) ``` **Arguments** - `number_of_columns` β€” The desired number of columns in the resultant table structure. If set to 0 or `Null`, the number of columns will be random from 1 to 128. Default value: `Null`. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) - `seed` β€” Random seed to produce stable results. If seed is not specified or set to `Null`, it is randomly generated. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Returned value** Randomly generated table structure. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT generateRandomStructure() ``` ``` c1 Decimal32(5), c2 Date, c3 Tuple(LowCardinality(String), Int128, UInt64, UInt16, UInt8, IPv6), c4 Array(UInt128), c5 UInt32, c6 IPv4, c7 Decimal256(64), c8 Decimal128(3), c9 UInt256, c10 UInt64, c11 DateTime ``` **with specified number of columns** ``` SELECT generateRandomStructure(1) ``` ``` c1 Map(UInt256, UInt16) ``` **with specified seed** ``` SELECT generateRandomStructure(NULL, 33) ``` ``` c1 DateTime, c2 Enum8('c2V0' = 0, 'c2V1' = 1, 'c2V2' = 2, 'c2V3' = 3), c3 LowCardinality(Nullable(FixedString(30))), c4 Int16, c5 Enum8('c5V0' = 0, 'c5V1' = 1, 'c5V2' = 2, 'c5V3' = 3), c6 Nullable(UInt8), c7 String, c8 Nested(e1 IPv4, e2 UInt8, e3 UInt16, e4 UInt16, e5 Int32, e6 Map(Date, Decimal256(70))) ``` ## generateSerialID[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#generateSerialID "Direct link to generateSerialID") Introduced in: v25.1.0 Generates and returns sequential numbers starting from the previous counter value. This function takes a string argument - a series identifier, and an optional starting value. The server should be configured with Keeper. The series are stored in Keeper nodes under the path, which can be configured in [`series_keeper_path`](https://clickhouse.com/docs/operations/server-configuration-parameters/settings#series_keeper_path) in the server configuration. **Syntax** ``` generateSerialID(series_identifier[, start_value]) ``` **Arguments** - `series_identifier` β€” Series identifier [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `start_value` β€” Optional. Starting value for the counter. Defaults to 0. Note: this value is only used when creating a new series and is ignored if the series already exists [`UInt*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Returned value** Returns sequential numbers starting from the previous counter value. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **first call** ``` SELECT generateSerialID('id1') ``` ``` β”Œβ”€generateSerialID('id1')──┐ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **second call** ``` SELECT generateSerialID('id1') ``` ``` β”Œβ”€generateSerialID('id1')──┐ β”‚ 2 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **column call** ``` SELECT *, generateSerialID('id1') FROM test_table ``` ``` β”Œβ”€CounterID─┬─UserID─┬─ver─┬─generateSerialID('id1')──┐ β”‚ 1 β”‚ 3 β”‚ 3 β”‚ 3 β”‚ β”‚ 1 β”‚ 1 β”‚ 1 β”‚ 4 β”‚ β”‚ 1 β”‚ 2 β”‚ 2 β”‚ 5 β”‚ β”‚ 1 β”‚ 5 β”‚ 5 β”‚ 6 β”‚ β”‚ 1 β”‚ 4 β”‚ 4 β”‚ 7 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **with start value** ``` SELECT generateSerialID('id2', 100) ``` ``` β”Œβ”€generateSerialID('id2', 100)──┐ β”‚ 100 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **with start value second call** ``` SELECT generateSerialID('id2', 100) ``` ``` β”Œβ”€generateSerialID('id2', 100)──┐ β”‚ 101 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## getClientHTTPHeader[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#getClientHTTPHeader "Direct link to getClientHTTPHeader") Introduced in: v24.5.0 Gets the value of an HTTP header. If there is no such header or the current request is not performed via the HTTP interface, the function returns an empty string. Certain HTTP headers (e.g., `Authentication` and `X-ClickHouse-*`) are restricted. Note Setting `allow_get_client_http_header` is required The function requires the setting `allow_get_client_http_header` to be enabled. The setting is not enabled by default for security reasons, because some headers, such as `Cookie`, could contain sensitive info. HTTP headers are case sensitive for this function. If the function is used in the context of a distributed query, it returns non-empty result only on the initiator node. **Syntax** ``` getClientHTTPHeader(name) ``` **Arguments** - `name` β€” The HTTP header name. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the value of the header. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT getClientHTTPHeader('Content-Type'); ``` ``` β”Œβ”€getClientHTTPHeader('Content-Type')─┐ β”‚ application/x-www-form-urlencoded β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## getMacro[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#getMacro "Direct link to getMacro") Introduced in: v20.1.0 Returns the value of a macro from the server configuration file. Macros are defined in the [`<macros>`](https://clickhouse.com/docs/operations/server-configuration-parameters/settings#macros) section of the configuration file and can be used to distinguish servers by convenient names even if they have complicated hostnames. If the function is executed in the context of a distributed table, it generates a normal column with values relevant to each shard. **Syntax** ``` getMacro(name) ``` **Arguments** - `name` β€” The name of the macro to retrieve. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the value of the specified macro. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Basic usage** ``` SELECT getMacro('test'); ``` ``` β”Œβ”€getMacro('test')─┐ β”‚ Value β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## getMaxTableNameLengthForDatabase[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#getMaxTableNameLengthForDatabase "Direct link to getMaxTableNameLengthForDatabase") Introduced in: v25.1.0 Returns the maximum table name length in a specified database. **Syntax** ``` getMaxTableNameLengthForDatabase(database_name) ``` **Arguments** - `database_name` β€” The name of the specified database. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the length of the maximum table name, an Integer **Examples** **typical** ``` SELECT getMaxTableNameLengthForDatabase('default'); ``` ``` β”Œβ”€getMaxTableNameLengthForDatabase('default')─┐ β”‚ 206 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## getMergeTreeSetting[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#getMergeTreeSetting "Direct link to getMergeTreeSetting") Introduced in: v25.6.0 Returns the current value of a MergeTree setting. **Syntax** ``` getMergeTreeSetting(setting_name) ``` **Arguments** - `setting_name` β€” The setting name. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the merge tree setting's current value. **Examples** **Usage example** ``` SELECT getMergeTreeSetting('index_granularity'); ``` ``` β”Œβ”€getMergeTreeSetting('index_granularity')─┐ β”‚ 8192 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## getOSKernelVersion[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#getOSKernelVersion "Direct link to getOSKernelVersion") Introduced in: v21.11.0 Returns a string with the OS kernel version. **Syntax** ``` getOSKernelVersion() ``` **Arguments** - None. **Returned value** Returns the current OS kernel version. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT getOSKernelVersion(); ``` ``` β”Œβ”€getOSKernelVersion()────┐ β”‚ Linux 4.15.0-55-generic β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## getServerPort[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#getServerPort "Direct link to getServerPort") Introduced in: v21.10.0 Returns the server's port number for a given protocol. **Syntax** ``` getServerPort(port_name) ``` **Arguments** - `port_name` β€” The name of the port. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the server port number. [`UInt16`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT getServerPort('tcp_port'); ``` ``` β”Œβ”€getServerPort('tcp_port')─┐ β”‚ 9000 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## getServerSetting[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#getServerSetting "Direct link to getServerSetting") Introduced in: v25.6.0 Returns the currently set value, given a server setting name. **Syntax** ``` getServerSetting(setting_name') ``` **Arguments** - `setting_name` β€” The server setting name. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the server setting's current value. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **Usage example** ``` SELECT getServerSetting('allow_use_jemalloc_memory'); ``` ``` β”Œβ”€getServerSetting('allow_use_jemalloc_memory')─┐ β”‚ true β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## getSetting[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#getSetting "Direct link to getSetting") Introduced in: v20.7.0 Returns the current value of a setting. **Syntax** ``` getSetting(setting_name) ``` **Arguments** - `setting_Name` β€” The setting name. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the setting's current value. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **Usage example** ``` SELECT getSetting('enable_analyzer'); SET enable_analyzer = false; SELECT getSetting('enable_analyzer'); ``` ``` β”Œβ”€getSetting('β‹―_analyzer')─┐ β”‚ true β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€getSetting('β‹―_analyzer')─┐ β”‚ false β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## getSettingOrDefault[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#getSettingOrDefault "Direct link to getSettingOrDefault") Introduced in: v24.10.0 Returns the current value of a setting or returns the default value specified in the second argument if the setting is not set in the current profile. **Syntax** ``` getSettingOrDefault(setting_name, default_value) ``` **Arguments** - `setting_name` β€” The setting name. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `default_value` β€” Value to return if custom\_setting is not set. Value may be of any data type or Null. **Returned value** Returns the current value of the specified setting or `default_value` if the setting is not set. **Examples** **Usage example** ``` SELECT getSettingOrDefault('custom_undef1', 'my_value'); SELECT getSettingOrDefault('custom_undef2', 100); SELECT getSettingOrDefault('custom_undef3', NULL); ``` ``` my_value 100 NULL ``` ## getSizeOfEnumType[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#getSizeOfEnumType "Direct link to getSizeOfEnumType") Introduced in: v1.1.0 Returns the number of fields in the given [`Enum`](https://clickhouse.com/docs/sql-reference/data-types/enum). **Syntax** ``` getSizeOfEnumType(x) ``` **Arguments** - `x` β€” Value of type `Enum`. [`Enum`](https://clickhouse.com/docs/sql-reference/data-types/enum) **Returned value** Returns the number of fields with `Enum` input values. [`UInt8/16`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT getSizeOfEnumType(CAST('a' AS Enum8('a' = 1, 'b' = 2))) AS x; ``` ``` β”Œβ”€x─┐ β”‚ 2 β”‚ β””β”€β”€β”€β”˜ ``` ## getSubcolumn[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#getSubcolumn "Direct link to getSubcolumn") Introduced in: v23.3.0 Receives the expression or identifier and constant string with the name of subcolumn. Returns requested subcolumn extracted from the expression. **Syntax** ``` getSubcolumn(nested_value, subcolumn_name) ``` **Arguments** - None. **Returned value** **Examples** **getSubcolumn** ``` SELECT getSubcolumn(array_col, 'size0'), getSubcolumn(tuple_col, 'elem_name') ``` ``` ``` ## getTypeSerializationStreams[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#getTypeSerializationStreams "Direct link to getTypeSerializationStreams") Introduced in: v22.6.0 Enumerates stream paths of a data type. This function is intended for developmental use. **Syntax** ``` getTypeSerializationStreams(col) ``` **Arguments** - `col` β€” Column or string representation of a data-type from which the data type will be detected. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns an array with all the serialization sub-stream paths. [`Array(String)`](https://clickhouse.com/docs/sql-reference/data-types/array) **Examples** **tuple** ``` SELECT getTypeSerializationStreams(tuple('a', 1, 'b', 2)) ``` ``` ['{TupleElement(1), Regular}','{TupleElement(2), Regular}','{TupleElement(3), Regular}','{TupleElement(4), Regular}'] ``` **map** ``` SELECT getTypeSerializationStreams('Map(String, Int64)') ``` ``` ['{ArraySizes}','{ArrayElements, TupleElement(keys), Regular}','{ArrayElements, TupleElement(values), Regular}'] ``` ## globalVariable[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#globalVariable "Direct link to globalVariable") Introduced in: v20.5.0 Takes a constant string argument and returns the value of the global variable with that name. This function is intended for compatibility with MySQL and not needed or useful for normal operation of ClickHouse. Only few dummy global variables are defined. **Syntax** ``` globalVariable(name) ``` **Arguments** - `name` β€” Global variable name. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the value of variable `name`. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **globalVariable** ``` SELECT globalVariable('max_allowed_packet') ``` ``` 67108864 ``` ## hasColumnInTable[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#hasColumnInTable "Direct link to hasColumnInTable") Introduced in: v1.1.0 Checks if a specific column exists in a database table. For elements in a nested data structure, the function checks for the existence of a column. For the nested data structure itself, the function returns `0`. **Syntax** ``` hasColumnInTable([hostname[, username[, password]],]database, table, column) ``` **Arguments** - `database` β€” Name of the database. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `table` β€” Name of the table. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `column` β€” Name of the column. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `hostname` β€” Optional. Remote server name to perform the check on. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `username` β€” Optional. Username for remote server. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `password` β€” Optional. Password for remote server. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns `1` if the given column exists, `0` otherwise. [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Check an existing column** ``` SELECT hasColumnInTable('system','metrics','metric') ``` ``` 1 ``` **Check a non-existing column** ``` SELECT hasColumnInTable('system','metrics','non-existing_column') ``` ``` 0 ``` ## hasThreadFuzzer[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#hasThreadFuzzer "Direct link to hasThreadFuzzer") Introduced in: v20.6.0 Returns whether the thread fuzzer is enabled. THis function is only useful for testing and debugging. **Syntax** ``` hasThreadFuzzer() ``` **Arguments** - None. **Returned value** Returns whether Thread Fuzzer is effective. [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Check Thread Fuzzer status** ``` SELECT hasThreadFuzzer() ``` ``` β”Œβ”€hasThreadFuzzer()─┐ β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## hostName[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#hostName "Direct link to hostName") Introduced in: v20.5.0 Returns the name of the host on which this function was executed. If the function executes on a remote server (distributed processing), the remote server name is returned. If the function executes in the context of a distributed table, it generates a normal column with values relevant to each shard. Otherwise it produces a constant value. **Syntax** ``` hostName() ``` **Aliases**: `hostname` **Arguments** - None. **Returned value** Returns the host name. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT hostName() ``` ``` β”Œβ”€hostName()─┐ β”‚ clickhouse β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## icebergBucket[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#icebergBucket "Direct link to icebergBucket") Introduced in: v25.5.0 Implements logic for the [iceberg bucket transform](https://iceberg.apache.org/spec/#bucket-transform-details.) **Syntax** ``` icebergBucket(N, value) ``` **Arguments** - `N` β€” The number of buckets, modulo. [`const (U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) - `value` β€” The source value to transform. [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Bool`](https://clickhouse.com/docs/sql-reference/data-types/boolean) or [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) or [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`FixedString`](https://clickhouse.com/docs/sql-reference/data-types/fixedstring) or [`UUID`](https://clickhouse.com/docs/sql-reference/data-types/uuid) or [`Date`](https://clickhouse.com/docs/sql-reference/data-types/date) or [`Time`](https://clickhouse.com/docs/sql-reference/data-types/time) or [`DateTime`](https://clickhouse.com/docs/sql-reference/data-types/datetime) **Returned value** Returns a 32-bit hash of the source value. [`Int32`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Example** ``` SELECT icebergBucket(5, 1.0 :: Float32) ``` ``` 4 ``` ## icebergTruncate[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#icebergTruncate "Direct link to icebergTruncate") Introduced in: v25.3.0 Implements logic of iceberg truncate transform: <https://iceberg.apache.org/spec/#truncate-transform-details>. **Syntax** ``` icebergTruncate(N, value) ``` **Arguments** - `value` β€” The value to transform. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) **Returned value** The same type as the argument **Examples** **Example** ``` SELECT icebergTruncate(3, 'iceberg') ``` ``` ice ``` ## identity[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#identity "Direct link to identity") Introduced in: v1.1.0 This function returns the argument you pass to it, which is useful for debugging and testing. It lets you bypass index usage to see full scan performance instead. The query analyzer ignores anything inside identity functions when looking for indexes to use, and it also disables constant folding. **Syntax** ``` identity(x) ``` **Arguments** - `x` β€” Input value. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns the input value unchanged. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **Usage example** ``` SELECT identity(42) ``` ``` 42 ``` ## ignore[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#ignore "Direct link to ignore") Introduced in: v1.1.0 Accepts arbitrary arguments and unconditionally returns `0`. **Syntax** ``` ignore(x) ``` **Arguments** - `x` β€” An input value which is unused and passed only so as to avoid a syntax error. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Always returns `0`. [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT ignore(0, 'ClickHouse', NULL) ``` ``` β”Œβ”€ignore(0, 'ClickHouse', NULL)─┐ β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## indexHint[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#indexHint "Direct link to indexHint") Introduced in: v1.1.0 This function is intended for debugging and introspection. It ignores its argument and always returns 1. The arguments are not evaluated. During index analysis, the argument of this function is assumed to not be wrapped in `indexHint`. This allows you to select data in index ranges by the corresponding condition but without further filtering by this condition. The index in ClickHouse is sparse and using `indexHint` will yield more data than specifying the same condition directly. Explanation When you run: ``` SELECT * FROM test WHERE key = 123; ``` ClickHouse does two things: 1. Uses the index to find which granules (blocks of ~8192 rows) might contain `key = 123` 2. Reads those granules and filters them row-by-row to return only rows where `key = 123` So even if it reads 8,192 rows from disk, it only returns the 1 row that actually matches. With `indexHint`, when you run: ``` SELECT * FROM test WHERE indexHint(key = 123); ``` ClickHouse does only one thing: 1. Uses the index to find which granules might contain key = 123 and returns all rows from those granules **without** filtering. It returns all 8,192 rows, including rows where `key = 456`, `key = 789`, etc. (Everything that happened to be stored in the same granule.) `indexHint()` is not for performance. It's for debugging and understanding how ClickHouse's index works: - Which granules does my condition select? - How many rows are in those granules? - Is my index being used effectively? Note: It is not possible to optimize a query with the `indexHint` function. The `indexHint` function does not optimize the query, as it does not provide any additional information for the query analysis. Having an expression inside the `indexHint` function is not anyhow better than without the `indexHint` function. The `indexHint` function can be used only for introspection and debugging purposes and it does not improve performance. If you see the usage of `indexHint` by anyone other than ClickHouse contributors, it is likely a mistake and you should remove it. **Syntax** ``` indexHint(expression) ``` **Arguments** - `expression` β€” Any expression for index range selection. [`Expression`](https://clickhouse.com/docs/sql-reference/data-types/special-data-types/expression) **Returned value** Returns `1` in all cases. [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example with date filtering** ``` SELECT FlightDate AS k, count() FROM ontime WHERE indexHint(k = '2025-09-15') GROUP BY k ORDER BY k ASC; ``` ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€k─┬─count()─┐ β”‚ 2025-09-14 β”‚ 7071 β”‚ β”‚ 2025-09-15 β”‚ 16428 β”‚ β”‚ 2025-09-16 β”‚ 1077 β”‚ β”‚ 2025-09-30 β”‚ 8167 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## initialQueryID[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#initialQueryID "Direct link to initialQueryID") Introduced in: v1.1.0 Returns the ID of the initial current query. Other parameters of a query can be extracted from field `initial_query_id` in [`system.query_log`](https://clickhouse.com/docs/operations/system-tables/query_log). In contrast to [`queryID`](https://clickhouse.com/docs/sql-reference/functions/other-functions#queryID) function, `initialQueryID` returns the same results on different shards. **Syntax** ``` initialQueryID() ``` **Aliases**: `initial_query_id` **Arguments** - None. **Returned value** Returns the ID of the initial current query. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` CREATE TABLE tmp (str String) ENGINE = Log; INSERT INTO tmp (*) VALUES ('a'); SELECT count(DISTINCT t) FROM (SELECT initialQueryID() AS t FROM remote('127.0.0.{1..3}', currentDatabase(), 'tmp') GROUP BY queryID()); ``` ``` β”Œβ”€count(DISTINCT t)─┐ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## initialQueryStartTime[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#initialQueryStartTime "Direct link to initialQueryStartTime") Introduced in: v25.4.0 Returns the start time of the initial current query. `initialQueryStartTime` returns the same results on different shards. **Syntax** ``` initialQueryStartTime() ``` **Aliases**: `initial_query_start_time` **Arguments** - None. **Returned value** Returns the start time of the initial current query. [`DateTime`](https://clickhouse.com/docs/sql-reference/data-types/datetime) **Examples** **Usage example** ``` CREATE TABLE tmp (str String) ENGINE = Log; INSERT INTO tmp (*) VALUES ('a'); SELECT count(DISTINCT t) FROM (SELECT initialQueryStartTime() AS t FROM remote('127.0.0.{1..3}', currentDatabase(), 'tmp') GROUP BY queryID()); ``` ``` β”Œβ”€count(DISTINCT t)─┐ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## initializeAggregation[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#initializeAggregation "Direct link to initializeAggregation") Introduced in: v20.6.0 Calculates the result of an aggregate function based on a single value. This function can be used to initialize aggregate functions with combinator [\-State](https://clickhouse.com/docs/sql-reference/aggregate-functions/combinators#-state). You can create states of aggregate functions and insert them to columns of type [`AggregateFunction`](https://clickhouse.com/docs/sql-reference/data-types/aggregatefunction) or use initialized aggregates as default values. **Syntax** ``` initializeAggregation(aggregate_function, arg1[, arg2, ...]) ``` **Arguments** - `aggregate_function` β€” Name of the aggregation function to initialize. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `arg1[, arg2, ...]` β€” Arguments of the aggregate function. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns the result of aggregation for every row passed to the function. The return type is the same as the return type of the function that `initializeAggregation` takes as a first argument. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **Basic usage with uniqState** ``` SELECT uniqMerge(state) FROM (SELECT initializeAggregation('uniqState', number % 3) AS state FROM numbers(10000)); ``` ``` β”Œβ”€uniqMerge(state)─┐ β”‚ 3 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Usage with sumState and finalizeAggregation** ``` SELECT finalizeAggregation(state), toTypeName(state) FROM (SELECT initializeAggregation('sumState', number % 3) AS state FROM numbers(5)); ``` ``` β”Œβ”€finalizeAggregation(state)─┬─toTypeName(state)─────────────┐ β”‚ 0 β”‚ AggregateFunction(sum, UInt8) β”‚ β”‚ 1 β”‚ AggregateFunction(sum, UInt8) β”‚ β”‚ 2 β”‚ AggregateFunction(sum, UInt8) β”‚ β”‚ 0 β”‚ AggregateFunction(sum, UInt8) β”‚ β”‚ 1 β”‚ AggregateFunction(sum, UInt8) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## isConstant[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#isConstant "Direct link to isConstant") Introduced in: v20.3.0 Returns whether the argument is a constant expression. A constant expression is an expression whose result is known during query analysis, i.e. before execution. For example, expressions over [literals](https://clickhouse.com/docs/sql-reference/syntax#literals) are constant expressions. This function is mostly intended for development, debugging and demonstration. **Syntax** ``` isConstant(x) ``` **Arguments** - `x` β€” An expression to check. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns `1` if `x` is constant, `0` if `x` is non-constant. [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Constant expression** ``` SELECT isConstant(x + 1) FROM (SELECT 43 AS x) ``` ``` β”Œβ”€isConstant(plus(x, 1))─┐ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Constant with function** ``` WITH 3.14 AS pi SELECT isConstant(cos(pi)) ``` ``` β”Œβ”€isConstant(cos(pi))─┐ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Non-constant expression** ``` SELECT isConstant(number) FROM numbers(1) ``` ``` β”Œβ”€isConstant(number)─┐ β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Behavior of the now() function** ``` SELECT isConstant(now()) ``` ``` β”Œβ”€isConstant(now())─┐ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## isDecimalOverflow[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#isDecimalOverflow "Direct link to isDecimalOverflow") Introduced in: v20.8.0 Checks if a decimal number has too many digits to fit properly in a Decimal data type with given precision. **Syntax** ``` isDecimalOverflow(value[, precision]) ``` **Arguments** - `value` β€” Decimal value to check. [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) - `precision` β€” Optional. The precision of the Decimal type. If omitted, the initial precision of the first argument is used. [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Returned value** Returns `1` if the decimal value has more digits than allowed by its precision, `0` if the decimal value satisfies the specified precision. [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT isDecimalOverflow(toDecimal32(1000000000, 0), 9), isDecimalOverflow(toDecimal32(1000000000, 0)), isDecimalOverflow(toDecimal32(-1000000000, 0), 9), isDecimalOverflow(toDecimal32(-1000000000, 0)); ``` ``` β”Œβ”€isDecimalOverflow(toDecimal32(1000000000, 0), 9)─┬─isDecimalOverflow(toDecimal32(1000000000, 0))─┬─isDecimalOverflow(toDecimal32(-1000000000, 0), 9)─┬─isDecimalOverflow(toDecimal32(-1000000000, 0))─┐ β”‚ 1 β”‚ 1 β”‚ 1 β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## joinGet[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#joinGet "Direct link to joinGet") Introduced in: v18.16.0 Allows you to extract data from a table the same way as from a dictionary. Gets data from Join tables using the specified join key. Note Only supports tables created with the `ENGINE = Join(ANY, LEFT, <join_keys>)` [statement](https://clickhouse.com/docs/engines/table-engines/special/join). **Syntax** ``` joinGet(join_storage_table_name, value_column, join_keys) ``` **Arguments** - `join_storage_table_name` β€” An identifier which indicates where to perform the search. The identifier is searched in the default database (see parameter `default_database` in the config file). To override the default database, use the `USE database_name` query or specify the database and the table through a dot, like `database_name.table_name`. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `value_column` β€” The name of the column of the table that contains required data. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `join_keys` β€” A list of join keys. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns list of values corresponded to list of keys. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **Usage example** ``` CREATE TABLE db_test.id_val(`id` UInt32, `val` UInt32) ENGINE = Join(ANY, LEFT, id); INSERT INTO db_test.id_val VALUES (1,11)(2,12)(4,13); SELECT joinGet(db_test.id_val, 'val', toUInt32(1)); ``` ``` β”Œβ”€joinGet(db_test.id_val, 'val', toUInt32(1))─┐ β”‚ 11 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Usage with table from current database** ``` USE db_test; SELECT joinGet(id_val, 'val', toUInt32(2)); ``` ``` β”Œβ”€joinGet(id_val, 'val', toUInt32(2))─┐ β”‚ 12 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Using arrays as join keys** ``` CREATE TABLE some_table (id1 UInt32, id2 UInt32, name String) ENGINE = Join(ANY, LEFT, id1, id2); INSERT INTO some_table VALUES (1, 11, 'a') (2, 12, 'b') (3, 13, 'c'); SELECT joinGet(some_table, 'name', 1, 11); ``` ``` β”Œβ”€joinGet(some_table, 'name', 1, 11)─┐ β”‚ a β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## joinGetOrNull[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#joinGetOrNull "Direct link to joinGetOrNull") Introduced in: v20.4.0 Allows you to extract data from a table the same way as from a dictionary. Gets data from Join tables using the specified join key. Unlike [`joinGet`](https://clickhouse.com/docs/sql-reference/functions/other-functions#joinGet) it returns `NULL` when the key is missing. Note Only supports tables created with the `ENGINE = Join(ANY, LEFT, <join_keys>)` [statement](https://clickhouse.com/docs/engines/table-engines/special/join). **Syntax** ``` joinGetOrNull(join_storage_table_name, value_column, join_keys) ``` **Arguments** - `join_storage_table_name` β€” An identifier which indicates where to perform the search. The identifier is searched in the default database (see parameter default\_database in the config file). To override the default database, use the `USE database_name` query or specify the database and the table through a dot, like `database_name.table_name`. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `value_column` β€” The name of the column of the table that contains required data. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `join_keys` β€” A list of join keys. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns a list of values corresponding to the list of keys, or `NULL` if a key is not found. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **Usage example** ``` CREATE TABLE db_test.id_val(`id` UInt32, `val` UInt32) ENGINE = Join(ANY, LEFT, id); INSERT INTO db_test.id_val VALUES (1,11)(2,12)(4,13); SELECT joinGetOrNull(db_test.id_val, 'val', toUInt32(1)), joinGetOrNull(db_test.id_val, 'val', toUInt32(999)); ``` ``` β”Œβ”€joinGetOrNull(db_test.id_val, 'val', toUInt32(1))─┬─joinGetOrNull(db_test.id_val, 'val', toUInt32(999))─┐ β”‚ 11 β”‚ ᴺᡁᴸᴸ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## lowCardinalityIndices[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#lowCardinalityIndices "Direct link to lowCardinalityIndices") Introduced in: v18.12.0 Returns the position of a value in the dictionary of a [LowCardinality](https://clickhouse.com/docs/sql-reference/data-types/lowcardinality) column. Positions start at 1. Since LowCardinality have per-part dictionaries, this function may return different positions for the same value in different parts. **Syntax** ``` lowCardinalityIndices(col) ``` **Arguments** - `col` β€” A low cardinality column. [`LowCardinality`](https://clickhouse.com/docs/sql-reference/data-types/lowcardinality) **Returned value** The position of the value in the dictionary of the current part. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage examples** ``` DROP TABLE IF EXISTS test; CREATE TABLE test (s LowCardinality(String)) ENGINE = Memory; -- create two parts: INSERT INTO test VALUES ('ab'), ('cd'), ('ab'), ('ab'), ('df'); INSERT INTO test VALUES ('ef'), ('cd'), ('ab'), ('cd'), ('ef'); SELECT s, lowCardinalityIndices(s) FROM test; ``` ``` β”Œβ”€s──┬─lowCardinalityIndices(s)─┐ β”‚ ab β”‚ 1 β”‚ β”‚ cd β”‚ 2 β”‚ β”‚ ab β”‚ 1 β”‚ β”‚ ab β”‚ 1 β”‚ β”‚ df β”‚ 3 β”‚ β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€s──┬─lowCardinalityIndices(s)─┐ β”‚ ef β”‚ 1 β”‚ β”‚ cd β”‚ 2 β”‚ β”‚ ab β”‚ 3 β”‚ β”‚ cd β”‚ 2 β”‚ β”‚ ef β”‚ 1 β”‚ β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## lowCardinalityKeys[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#lowCardinalityKeys "Direct link to lowCardinalityKeys") Introduced in: v18.12.0 Returns the dictionary values of a [LowCardinality](https://clickhouse.com/docs/sql-reference/data-types/lowcardinality) column. If the block is smaller or larger than the dictionary size, the result will be truncated or extended with default values. Since LowCardinality have per-part dictionaries, this function may return different dictionary values in different parts. **Syntax** ``` lowCardinalityKeys(col) ``` **Arguments** - `col` β€” A low cardinality column. [`LowCardinality`](https://clickhouse.com/docs/sql-reference/data-types/lowcardinality) **Returned value** Returns the dictionary keys. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **lowCardinalityKeys** ``` DROP TABLE IF EXISTS test; CREATE TABLE test (s LowCardinality(String)) ENGINE = Memory; -- create two parts: INSERT INTO test VALUES ('ab'), ('cd'), ('ab'), ('ab'), ('df'); INSERT INTO test VALUES ('ef'), ('cd'), ('ab'), ('cd'), ('ef'); SELECT s, lowCardinalityKeys(s) FROM test; ``` ``` β”Œβ”€s──┬─lowCardinalityKeys(s)─┐ β”‚ ef β”‚ β”‚ β”‚ cd β”‚ ef β”‚ β”‚ ab β”‚ cd β”‚ β”‚ cd β”‚ ab β”‚ β”‚ ef β”‚ β”‚ β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€s──┬─lowCardinalityKeys(s)─┐ β”‚ ab β”‚ β”‚ β”‚ cd β”‚ ab β”‚ β”‚ ab β”‚ cd β”‚ β”‚ ab β”‚ df β”‚ β”‚ df β”‚ β”‚ β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## materialize[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#materialize "Direct link to materialize") Introduced in: v1.1.0 Turns a constant into a full column containing a single value. Full columns and constants are represented differently in memory. Functions usually execute different code for normal and constant arguments, although the result should typically be the same. This function can be used to debug this behavior. **Syntax** ``` materialize(x) ``` **Arguments** - `x` β€” A constant. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns a full column containing the constant value. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **Usage example** ``` -- In the example below the `countMatches` function expects a constant second argument. -- This behaviour can be debugged by using the `materialize` function to turn a constant into a full column, -- verifying that the function throws an error for a non-constant argument. SELECT countMatches('foobarfoo', 'foo'); SELECT countMatches('foobarfoo', materialize('foo')); ``` ``` 2 Code: 44. DB::Exception: Received from localhost:9000. DB::Exception: Illegal type of argument #2 'pattern' of function countMatches, expected constant String, got String ``` ## minSampleSizeContinuous[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#minSampleSizeContinuous "Direct link to minSampleSizeContinuous") Introduced in: v23.10.0 Calculates the minimum required sample size for an A/B test comparing means of a continuous metric in two samples. Uses the formula described in [this article](https://towardsdatascience.com/required-sample-size-for-a-b-testing-6f6608dd330a). Assumes equal sizes of treatment and control groups. Returns the required sample size for one group (i.e. the sample size required for the whole experiment is twice the returned value). Also assumes equal variance of the test metric in treatment and control groups. **Syntax** ``` minSampleSizeContinuous(baseline, sigma, mde, power, alpha) ``` **Aliases**: `minSampleSizeContinous` **Arguments** - `baseline` β€” Baseline value of a metric. [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) - `sigma` β€” Baseline standard deviation of a metric. [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) - `mde` β€” Minimum detectable effect (MDE) as percentage of the baseline value (e.g. for a baseline value 112.25 the MDE 0.03 means an expected change to 112.25 Β± 112.25\*0.03). [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) - `power` β€” Required statistical power of a test (1 - probability of Type II error). [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) - `alpha` β€” Required significance level of a test (probability of Type I error). [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) **Returned value** Returns a named Tuple with 3 elements: `minimum_sample_size`, `detect_range_lower` and `detect_range_upper`. These are respectively: the required sample size, the lower bound of the range of values not detectable with the returned required sample size, calculated as `baseline * (1 - mde)`, and the upper bound of the range of values not detectable with the returned required sample size, calculated as `baseline * (1 + mde)` (Float64). [`Tuple(Float64, Float64, Float64)`](https://clickhouse.com/docs/sql-reference/data-types/tuple) **Examples** **minSampleSizeContinuous** ``` SELECT minSampleSizeContinuous(112.25, 21.1, 0.03, 0.80, 0.05) AS sample_size ``` ``` (616.2931945826209,108.8825,115.6175) ``` ## minSampleSizeConversion[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#minSampleSizeConversion "Direct link to minSampleSizeConversion") Introduced in: v22.6.0 Calculates minimum required sample size for an A/B test comparing conversions (proportions) in two samples. Uses the formula described in [this article](https://towardsdatascience.com/required-sample-size-for-a-b-testing-6f6608dd330a). Assumes equal sizes of treatment and control groups. Returns the sample size required for one group (i.e. the sample size required for the whole experiment is twice the returned value). **Syntax** ``` minSampleSizeConversion(baseline, mde, power, alpha) ``` **Arguments** - `baseline` β€” Baseline conversion. [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) - `mde` β€” Minimum detectable effect (MDE) as percentage points (e.g. for a baseline conversion 0.25 the MDE 0.03 means an expected change to 0.25 Β± 0.03). [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) - `power` β€” Required statistical power of a test (1 - probability of Type II error). [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) - `alpha` β€” Required significance level of a test (probability of Type I error). [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) **Returned value** Returns a named Tuple with 3 elements: `minimum_sample_size`, `detect_range_lower`, `detect_range_upper`. These are, respectively: the required sample size, the lower bound of the range of values not detectable with the returned required sample size, calculated as `baseline - mde`, the upper bound of the range of values not detectable with the returned required sample size, calculated as `baseline + mde`. [`Tuple(Float64, Float64, Float64)`](https://clickhouse.com/docs/sql-reference/data-types/tuple) **Examples** **minSampleSizeConversion** ``` SELECT minSampleSizeConversion(0.25, 0.03, 0.80, 0.05) AS sample_size ``` ``` (3396.077603219163,0.22,0.28) ``` ## neighbor[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#neighbor "Direct link to neighbor") Introduced in: v20.1.0 Returns a value from a column at a specified offset from the current row. This function is deprecated and error-prone because it operates on the physical order of data blocks which may not correspond to the logical order expected by users. Consider using proper window functions instead. The function can be enabled by setting `allow_deprecated_error_prone_window_functions = 1`. **Syntax** ``` neighbor(column, offset[, default_value]) ``` **Arguments** - `column` β€” The source column. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) - `offset` β€” The offset from the current row. Positive values look forward, negative values look backward. [`Integer`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) - `default_value` β€” Optional. The value to return if the offset goes beyond the data bounds. If not specified, uses the default value for the column type. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns a value from the specified offset, or default if out of bounds. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **Usage example** ``` SELECT number, neighbor(number, 2) FROM system.numbers LIMIT 10; ``` ``` β”Œβ”€number─┬─neighbor(number, 2)─┐ β”‚ 0 β”‚ 2 β”‚ β”‚ 1 β”‚ 3 β”‚ β”‚ 2 β”‚ 4 β”‚ β”‚ 3 β”‚ 5 β”‚ β”‚ 4 β”‚ 6 β”‚ β”‚ 5 β”‚ 7 β”‚ β”‚ 6 β”‚ 8 β”‚ β”‚ 7 β”‚ 9 β”‚ β”‚ 8 β”‚ 0 β”‚ β”‚ 9 β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **With default value** ``` SELECT number, neighbor(number, 2, 999) FROM system.numbers LIMIT 10; ``` ``` β”Œβ”€number─┬─neighbor(number, 2, 999)─┐ β”‚ 0 β”‚ 2 β”‚ β”‚ 1 β”‚ 3 β”‚ β”‚ 2 β”‚ 4 β”‚ β”‚ 3 β”‚ 5 β”‚ β”‚ 4 β”‚ 6 β”‚ β”‚ 5 β”‚ 7 β”‚ β”‚ 6 β”‚ 8 β”‚ β”‚ 7 β”‚ 9 β”‚ β”‚ 8 β”‚ 999 β”‚ β”‚ 9 β”‚ 999 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## normalizeQuery[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#normalizeQuery "Direct link to normalizeQuery") Introduced in: v20.8.0 Replaces literals, sequences of literals and complex aliases (containing whitespace, more than two digits or at least 36 bytes long such as UUIDs) with placeholder `?`. **Syntax** ``` normalizeQuery(x) ``` **Arguments** - `x` β€” Sequence of characters. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the given sequence of characters with placeholders. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT normalizeQuery('[1, 2, 3, x]') AS query ``` ``` β”Œβ”€query────┐ β”‚ [?.., x] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## normalizeQueryKeepNames[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#normalizeQueryKeepNames "Direct link to normalizeQueryKeepNames") Introduced in: v21.2.0 Replaces literals and sequences of literals with placeholder `?` but does not replace complex aliases (containing whitespace, more than two digits or at least 36 bytes long such as UUIDs). This helps better analyze complex query logs. **Syntax** ``` normalizeQueryKeepNames(x) ``` **Arguments** - `x` β€” Sequence of characters. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the given sequence of characters with placeholders. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT normalizeQuery('SELECT 1 AS aComplexName123'), normalizeQueryKeepNames('SELECT 1 AS aComplexName123') ``` ``` β”Œβ”€normalizeQuery('SELECT 1 AS aComplexName123')─┬─normalizeQueryKeepNames('SELECT 1 AS aComplexName123')─┐ β”‚ SELECT ? AS `?` β”‚ SELECT ? AS aComplexName123 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## normalizedQueryHash[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#normalizedQueryHash "Direct link to normalizedQueryHash") Introduced in: v20.8.0 Returns identical 64 bit hash values without the values of literals for similar queries. Can be helpful in analyzing query logs. **Syntax** ``` normalizedQueryHash(x) ``` **Arguments** - `x` β€” Sequence of characters. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns a 64 bit hash value. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT normalizedQueryHash('SELECT 1 AS `xyz`') != normalizedQueryHash('SELECT 1 AS `abc`') AS res ``` ``` β”Œβ”€res─┐ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”˜ ``` ## normalizedQueryHashKeepNames[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#normalizedQueryHashKeepNames "Direct link to normalizedQueryHashKeepNames") Introduced in: v21.2.0 Like [`normalizedQueryHash`](https://clickhouse.com/docs/sql-reference/functions/other-functions#normalizedQueryHash) it returns identical 64 bit hash values without the values of literals for similar queries, but it does not replace complex aliases (containing whitespace, more than two digits or at least 36 bytes long such as UUIDs) with a placeholder before hashing. Can be helpful in analyzing query logs. **Syntax** ``` normalizedQueryHashKeepNames(x) ``` **Arguments** - `x` β€” Sequence of characters. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns a 64 bit hash value. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT normalizedQueryHash('SELECT 1 AS `xyz123`') != normalizedQueryHash('SELECT 1 AS `abc123`') AS normalizedQueryHash; SELECT normalizedQueryHashKeepNames('SELECT 1 AS `xyz123`') != normalizedQueryHashKeepNames('SELECT 1 AS `abc123`') AS normalizedQueryHashKeepNames; ``` ``` β”Œβ”€normalizedQueryHash─┐ β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€normalizedQueryHashKeepNames─┐ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## parseReadableSize[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#parseReadableSize "Direct link to parseReadableSize") Introduced in: v24.6.0 Given a string containing a byte size and `B`, `KiB`, `KB`, `MiB`, `MB`, etc. as a unit (i.e. [ISO/IEC 80000-13](https://en.wikipedia.org/wiki/ISO/IEC_80000) or decimal byte unit), this function returns the corresponding number of bytes. If the function is unable to parse the input value, it throws an exception. The inverse operations of this function are [`formatReadableSize`](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatReadableSize) and [`formatReadableDecimalSize`](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatReadableDecimalSize). **Syntax** ``` parseReadableSize(x) ``` **Arguments** - `x` β€” Readable size with ISO/IEC 80000-13 or decimal byte unit. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the number of bytes, rounded up to the nearest integer. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT arrayJoin(['1 B', '1 KiB', '3 MB', '5.314 KiB']) AS readable_sizes, parseReadableSize(readable_sizes) AS sizes; ``` ``` β”Œβ”€readable_sizes─┬───sizes─┐ β”‚ 1 B β”‚ 1 β”‚ β”‚ 1 KiB β”‚ 1024 β”‚ β”‚ 3 MB β”‚ 3000000 β”‚ β”‚ 5.314 KiB β”‚ 5442 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## parseReadableSizeOrNull[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#parseReadableSizeOrNull "Direct link to parseReadableSizeOrNull") Introduced in: v24.6.0 Given a string containing a byte size and `B`, `KiB`, `KB`, `MiB`, `MB`, etc. as a unit (i.e. [ISO/IEC 80000-13](https://en.wikipedia.org/wiki/ISO/IEC_80000) or decimal byte unit), this function returns the corresponding number of bytes. If the function is unable to parse the input value, it returns `NULL`. The inverse operations of this function are [`formatReadableSize`](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatReadableSize) and [`formatReadableDecimalSize`](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatReadableDecimalSize). **Syntax** ``` parseReadableSizeOrNull(x) ``` **Arguments** - `x` β€” Readable size with ISO/IEC 80000-13 or decimal byte unit. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the number of bytes, rounded up to the nearest integer, or `NULL` if unable to parse the input [`Nullable(UInt64)`](https://clickhouse.com/docs/sql-reference/data-types/nullable) **Examples** **Usage example** ``` SELECT arrayJoin(['1 B', '1 KiB', '3 MB', '5.314 KiB', 'invalid']) AS readable_sizes, parseReadableSizeOrNull(readable_sizes) AS sizes; ``` ``` β”Œβ”€readable_sizes─┬───sizes─┐ β”‚ 1 B β”‚ 1 β”‚ β”‚ 1 KiB β”‚ 1024 β”‚ β”‚ 3 MB β”‚ 3000000 β”‚ β”‚ 5.314 KiB β”‚ 5442 β”‚ β”‚ invalid β”‚ ᴺᡁᴸᴸ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## parseReadableSizeOrZero[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#parseReadableSizeOrZero "Direct link to parseReadableSizeOrZero") Introduced in: v24.6.0 Given a string containing a byte size and `B`, `KiB`, `KB`, `MiB`, `MB`, etc. as a unit (i.e. [ISO/IEC 80000-13](https://en.wikipedia.org/wiki/ISO/IEC_80000) or decimal byte unit), this function returns the corresponding number of bytes. If the function is unable to parse the input value, it returns `0`. The inverse operations of this function are [`formatReadableSize`](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatReadableSize) and [`formatReadableDecimalSize`](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatReadableDecimalSize). **Syntax** ``` parseReadableSizeOrZero(x) ``` **Arguments** - `x` β€” Readable size with ISO/IEC 80000-13 or decimal byte unit. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the number of bytes, rounded up to the nearest integer, or `0` if unable to parse the input. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT arrayJoin(['1 B', '1 KiB', '3 MB', '5.314 KiB', 'invalid']) AS readable_sizes, parseReadableSizeOrZero(readable_sizes) AS sizes; ``` ``` β”Œβ”€readable_sizes─┬───sizes─┐ β”‚ 1 B β”‚ 1 β”‚ β”‚ 1 KiB β”‚ 1024 β”‚ β”‚ 3 MB β”‚ 3000000 β”‚ β”‚ 5.314 KiB β”‚ 5442 β”‚ β”‚ invalid β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## parseTimeDelta[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#parseTimeDelta "Direct link to parseTimeDelta") Introduced in: v22.7.0 Parse a sequence of numbers followed by something resembling a time unit. The time delta string uses these time unit specifications: - `years`, `year`, `yr`, `y` - `months`, `month`, `mo` - `weeks`, `week`, `w` - `days`, `day`, `d` - `hours`, `hour`, `hr`, `h` - `minutes`, `minute`, `min`, `m` - `seconds`, `second`, `sec`, `s` - `milliseconds`, `millisecond`, `millisec`, `ms` - `microseconds`, `microsecond`, `microsec`, `ΞΌs`, `Β΅s`, `us` - `nanoseconds`, `nanosecond`, `nanosec`, `ns` Multiple time units can be combined with separators (space, `;`, `-`, `+`, `,`, `:`). The length of years and months are approximations: year is 365 days, month is 30.5 days. **Syntax** ``` parseTimeDelta(timestr) ``` **Arguments** - `timestr` β€” A sequence of numbers followed by something resembling a time unit. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** The number of seconds. [`Float64`](https://clickhouse.com/docs/sql-reference/data-types/float) **Examples** **Usage example** ``` SELECT parseTimeDelta('11s+22min') ``` ``` β”Œβ”€parseTimeDelta('11s+22min')─┐ β”‚ 1331 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Complex time units** ``` SELECT parseTimeDelta('1yr2mo') ``` ``` β”Œβ”€parseTimeDelta('1yr2mo')─┐ β”‚ 36806400 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## partitionId[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#partitionId "Direct link to partitionId") Introduced in: v21.4.0 Computes the [partition ID](https://clickhouse.com/docs/engines/table-engines/mergetree-family/custom-partitioning-key). Note This function is slow and should not be called for large numbers of rows. **Syntax** ``` partitionId(column1[, column2, ...]) ``` **Aliases**: `partitionID` **Arguments** - `column1, column2, ...` β€” Column for which to return the partition ID. **Returned value** Returns the partition ID that the row belongs to. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` DROP TABLE IF EXISTS tab; CREATE TABLE tab ( i int, j int ) ENGINE = MergeTree PARTITION BY i ORDER BY tuple(); INSERT INTO tab VALUES (1, 1), (1, 2), (1, 3), (2, 4), (2, 5), (2, 6); SELECT i, j, partitionId(i), _partition_id FROM tab ORDER BY i, j; ``` ``` β”Œβ”€i─┬─j─┬─partitionId(i)─┬─_partition_id─┐ β”‚ 1 β”‚ 1 β”‚ 1 β”‚ 1 β”‚ β”‚ 1 β”‚ 2 β”‚ 1 β”‚ 1 β”‚ β”‚ 1 β”‚ 3 β”‚ 1 β”‚ 1 β”‚ β”‚ 2 β”‚ 4 β”‚ 2 β”‚ 2 β”‚ β”‚ 2 β”‚ 5 β”‚ 2 β”‚ 2 β”‚ β”‚ 2 β”‚ 6 β”‚ 2 β”‚ 2 β”‚ β””β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## queryID[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#queryID "Direct link to queryID") Introduced in: v21.9.0 Returns the ID of the current query. Other parameters of a query can be extracted from field `query_id` in the [`system.query_log`](https://clickhouse.com/docs/operations/system-tables/query_log) table. In contrast to [`initialQueryID`](https://clickhouse.com/docs/sql-reference/functions/other-functions#initialQueryID) function, `queryID` can return different results on different shards. **Syntax** ``` queryID() ``` **Aliases**: `query_id` **Arguments** - None. **Returned value** Returns the ID of the current query. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` CREATE TABLE tmp (str String) ENGINE = Log; INSERT INTO tmp (*) VALUES ('a'); SELECT count(DISTINCT t) FROM (SELECT queryID() AS t FROM remote('127.0.0.{1..3}', currentDatabase(), 'tmp') GROUP BY queryID()); ``` ``` β”Œβ”€count(DISTINCT t)─┐ β”‚ 3 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## revision[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#revision "Direct link to revision") Introduced in: v22.7.0 Returns the current ClickHouse server revision. **Syntax** ``` revision() ``` **Arguments** - None. **Returned value** Returns the current ClickHouse server revision. [`UInt32`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT revision() ``` ``` β”Œβ”€revision()─┐ β”‚ 54485 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## rowNumberInAllBlocks[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#rowNumberInAllBlocks "Direct link to rowNumberInAllBlocks") Introduced in: v1.1.0 Returns a unique row number for each row processed. **Syntax** ``` rowNumberInAllBlocks() ``` **Arguments** - None. **Returned value** Returns the ordinal number of the row in the data block starting from `0`. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT rowNumberInAllBlocks() FROM ( SELECT * FROM system.numbers_mt LIMIT 10 ) SETTINGS max_block_size = 2 ``` ``` β”Œβ”€rowNumberInAllBlocks()─┐ β”‚ 0 β”‚ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€rowNumberInAllBlocks()─┐ β”‚ 4 β”‚ β”‚ 5 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€rowNumberInAllBlocks()─┐ β”‚ 2 β”‚ β”‚ 3 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€rowNumberInAllBlocks()─┐ β”‚ 6 β”‚ β”‚ 7 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€rowNumberInAllBlocks()─┐ β”‚ 8 β”‚ β”‚ 9 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## rowNumberInBlock[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#rowNumberInBlock "Direct link to rowNumberInBlock") Introduced in: v1.1.0 For each [block](https://clickhouse.com/docs/development/architecture#block) processed by `rowNumberInBlock`, returns the number of the current row. The returned number starts from 0 for each block. **Syntax** ``` rowNumberInBlock() ``` **Arguments** - None. **Returned value** Returns the ordinal number of the row in the data block starting from `0`. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT rowNumberInBlock() FROM ( SELECT * FROM system.numbers_mt LIMIT 10 ) SETTINGS max_block_size = 2 ``` ``` β”Œβ”€rowNumberInBlock()─┐ β”‚ 0 β”‚ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€rowNumberInBlock()─┐ β”‚ 0 β”‚ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€rowNumberInBlock()─┐ β”‚ 0 β”‚ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€rowNumberInBlock()─┐ β”‚ 0 β”‚ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€rowNumberInBlock()─┐ β”‚ 0 β”‚ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## runningAccumulate[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#runningAccumulate "Direct link to runningAccumulate") Introduced in: v1.1.0 Accumulates the states of an aggregate function for each row of a data block. Deprecated The state is reset for each new block of data. Due to this error-prone behavior the function has been deprecated, and you are advised to use [window functions](https://clickhouse.com/docs/sql-reference/window-functions) instead. You can use setting [`allow_deprecated_error_prone_window_functions`](https://clickhouse.com/docs/operations/settings/settings#allow_deprecated_error_prone_window_functions) to allow usage of this function. **Syntax** ``` runningAccumulate(agg_state[, grouping]) ``` **Arguments** - `agg_state` β€” State of the aggregate function. [`AggregateFunction`](https://clickhouse.com/docs/sql-reference/data-types/aggregatefunction) - `grouping` β€” Optional. Grouping key. The state of the function is reset if the `grouping` value is changed. It can be any of the supported data types for which the equality operator is defined. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns the accumulated result for each row. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **Usage example with initializeAggregation** ``` WITH initializeAggregation('sumState', number) AS one_row_sum_state SELECT number, finalizeAggregation(one_row_sum_state) AS one_row_sum, runningAccumulate(one_row_sum_state) AS cumulative_sum FROM numbers(5); ``` ``` β”Œβ”€number─┬─one_row_sum─┬─cumulative_sum─┐ β”‚ 0 β”‚ 0 β”‚ 0 β”‚ β”‚ 1 β”‚ 1 β”‚ 1 β”‚ β”‚ 2 β”‚ 2 β”‚ 3 β”‚ β”‚ 3 β”‚ 3 β”‚ 6 β”‚ β”‚ 4 β”‚ 4 β”‚ 10 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## runningConcurrency[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#runningConcurrency "Direct link to runningConcurrency") Introduced in: v21.3.0 Calculates the number of concurrent events. Each event has a start time and an end time. The start time is included in the event, while the end time is excluded. Columns with a start time and an end time must be of the same data type. The function calculates the total number of active (concurrent) events for each event start time. Requirements Events must be ordered by the start time in ascending order. If this requirement is violated the function raises an exception. Every data block is processed separately. If events from different data blocks overlap then they can not be processed correctly. Deprecated It is advised to use [window functions](https://clickhouse.com/docs/sql-reference/window-functions) instead. **Syntax** ``` runningConcurrency(start, end) ``` **Arguments** - `start` β€” A column with the start time of events. [`Date`](https://clickhouse.com/docs/sql-reference/data-types/date) or [`DateTime`](https://clickhouse.com/docs/sql-reference/data-types/datetime) or [`DateTime64`](https://clickhouse.com/docs/sql-reference/data-types/datetime64) - `end` β€” A column with the end time of events. [`Date`](https://clickhouse.com/docs/sql-reference/data-types/date) or [`DateTime`](https://clickhouse.com/docs/sql-reference/data-types/datetime) or [`DateTime64`](https://clickhouse.com/docs/sql-reference/data-types/datetime64) **Returned value** Returns the number of concurrent events at each event start time. [`UInt32`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT start, runningConcurrency(start, end) FROM example_table; ``` ``` β”Œβ”€β”€β”€β”€β”€β”€start─┬─runningConcurrency(start, end)─┐ β”‚ 2025-03-03 β”‚ 1 β”‚ β”‚ 2025-03-06 β”‚ 2 β”‚ β”‚ 2025-03-07 β”‚ 3 β”‚ β”‚ 2025-03-11 β”‚ 2 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## runningDifference[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#runningDifference "Direct link to runningDifference") Introduced in: v1.1.0 Calculates the difference between two consecutive row values in the data block. Returns `0` for the first row, and for subsequent rows the difference to the previous row. Deprecated Only returns differences inside the currently processed data block. Because of this error-prone behavior, the function is deprecated. It is advised to use [window functions](https://clickhouse.com/docs/sql-reference/window-functions) instead. You can use setting [`allow_deprecated_error_prone_window_functions`](https://clickhouse.com/docs/operations/settings/settings#allow_deprecated_error_prone_window_functions) to allow usage of this function. The result of the function depends on the affected data blocks and the order of data in the block. The order of rows during calculation of `runningDifference()` can differ from the order of rows returned to the user. To prevent that you can create a subquery with [`ORDER BY`](https://clickhouse.com/docs/sql-reference/statements/select/order-by) and call the function from outside the subquery. Please note that the block size affects the result. The internal state of `runningDifference` state is reset for each new block. **Syntax** ``` runningDifference(x) ``` **Arguments** - `x` β€” Column for which to calculate the running difference. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns the difference between consecutive values, with 0 for the first row. **Examples** **Usage example** ``` SELECT EventID, EventTime, runningDifference(EventTime) AS delta FROM ( SELECT EventID, EventTime FROM events WHERE EventDate = '2025-11-24' ORDER BY EventTime ASC LIMIT 5 ); ``` ``` β”Œβ”€EventID─┬───────────EventTime─┬─delta─┐ β”‚ 1106 β”‚ 2025-11-24 00:00:04 β”‚ 0 β”‚ β”‚ 1107 β”‚ 2025-11-24 00:00:05 β”‚ 1 β”‚ β”‚ 1108 β”‚ 2025-11-24 00:00:05 β”‚ 0 β”‚ β”‚ 1109 β”‚ 2025-11-24 00:00:09 β”‚ 4 β”‚ β”‚ 1110 β”‚ 2025-11-24 00:00:10 β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Block size impact example** ``` SELECT number, runningDifference(number + 1) AS diff FROM numbers(100000) WHERE diff != 1; ``` ``` β”Œβ”€number─┬─diff─┐ β”‚ 0 β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€number─┬─diff─┐ β”‚ 65536 β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”˜ ``` ## runningDifferenceStartingWithFirstValue[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#runningDifferenceStartingWithFirstValue "Direct link to runningDifferenceStartingWithFirstValue") Introduced in: v1.1.0 Calculates the difference between consecutive row values in a data block, but unlike [`runningDifference`](https://clickhouse.com/docs/sql-reference/functions/other-functions#runningDifference), it returns the actual value of the first row instead of `0`. Deprecated Only returns differences inside the currently processed data block. Because of this error-prone behavior, the function is deprecated. It is advised to use [window functions](https://clickhouse.com/docs/sql-reference/window-functions) instead. You can use setting `allow_deprecated_error_prone_window_functions` to allow usage of this function. **Syntax** ``` runningDifferenceStartingWithFirstValue(x) ``` **Arguments** - `x` β€” Column for which to calculate the running difference. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns the difference between consecutive values, with the first row's value for the first row. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **Usage example** ``` SELECT number, runningDifferenceStartingWithFirstValue(number) AS diff FROM numbers(5); ``` ``` β”Œβ”€number─┬─diff─┐ β”‚ 0 β”‚ 0 β”‚ β”‚ 1 β”‚ 1 β”‚ β”‚ 2 β”‚ 1 β”‚ β”‚ 3 β”‚ 1 β”‚ β”‚ 4 β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”˜ ``` ## serverUUID[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#serverUUID "Direct link to serverUUID") Introduced in: v20.1.0 Returns the random and unique UUID (v4) generated when the server is first started. The UUID is persisted, i.e. the second, third, etc. server start return the same UUID. **Syntax** ``` serverUUID() ``` **Arguments** - None. **Returned value** Returns the random UUID of the server. [`UUID`](https://clickhouse.com/docs/sql-reference/data-types/uuid) **Examples** **Usage example** ``` SELECT serverUUID(); ``` ``` β”Œβ”€serverUUID()─────────────────────────────┐ β”‚ 7ccc9260-000d-4d5c-a843-5459abaabb5f β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## shardCount[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#shardCount "Direct link to shardCount") Introduced in: v21.9.0 Returns the total number of shards for a distributed query. If a query is not distributed then constant value `0` is returned. **Syntax** ``` shardCount() ``` **Arguments** - None. **Returned value** Returns the total number of shards or `0`. [`UInt32`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` -- See shardNum() example above which also demonstrates shardCount() CREATE TABLE shard_count_example (dummy UInt8) ENGINE=Distributed(test_cluster_two_shards_localhost, system, one, dummy); SELECT shardCount() FROM shard_count_example; ``` ``` β”Œβ”€shardCount()─┐ β”‚ 2 β”‚ β”‚ 2 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## shardNum[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#shardNum "Direct link to shardNum") Introduced in: v21.9.0 Returns the index of a shard which processes a part of data in a distributed query. Indices begin from `1`. If a query is not distributed then a constant value `0` is returned. **Syntax** ``` shardNum() ``` **Arguments** - None. **Returned value** Returns the shard index or a constant `0`. [`UInt32`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` CREATE TABLE shard_num_example (dummy UInt8) ENGINE=Distributed(test_cluster_two_shards_localhost, system, one, dummy); SELECT dummy, shardNum(), shardCount() FROM shard_num_example; ``` ``` β”Œβ”€dummy─┬─shardNum()─┬─shardCount()─┐ β”‚ 0 β”‚ 1 β”‚ 2 β”‚ β”‚ 0 β”‚ 2 β”‚ 2 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## showCertificate[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#showCertificate "Direct link to showCertificate") Introduced in: v22.6.0 Shows information about the current server's Secure Sockets Layer (SSL) certificate if it has been configured. See [Configuring TLS](https://clickhouse.com/docs/guides/sre/tls/configuring-tls) for more information on how to configure ClickHouse to use OpenSSL certificates to validate connections. **Syntax** ``` showCertificate() ``` **Arguments** - None. **Returned value** Returns map of key-value pairs relating to the configured SSL certificate. [`Map(String, String)`](https://clickhouse.com/docs/sql-reference/data-types/map) **Examples** **Usage example** ``` SELECT showCertificate() FORMAT LineAsString; ``` ``` {'version':'1','serial_number':'2D9071D64530052D48308473922C7ADAFA85D6C5','signature_algo':'sha256WithRSAEncryption','issuer':'/CN=marsnet.local CA','not_before':'May 7 17:01:21 2024 GMT','not_after':'May 7 17:01:21 2025 GMT','subject':'/CN=chnode1','pkey_algo':'rsaEncryption'} ``` ## sleep[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#sleep "Direct link to sleep") Introduced in: v1.1.0 Pauses the execution of a query by the specified number of seconds. The function is primarily used for testing and debugging purposes. The `sleep()` function should generally not be used in production environments, as it can negatively impact query performance and system responsiveness. However, it can be useful in the following scenarios: 1. **Testing**: When testing or benchmarking ClickHouse, you may want to simulate delays or introduce pauses to observe how the system behaves under certain conditions. 2. **Debugging**: If you need to examine the state of the system or the execution of a query at a specific point in time, you can use `sleep()` to introduce a pause, allowing you to inspect or collect relevant information. 3. **Simulation**: In some cases, you may want to simulate real-world scenarios where delays or pauses occur, such as network latency or external system dependencies. Note It's important to use the `sleep()` function judiciously and only when necessary, as it can potentially impact the overall performance and responsiveness of your ClickHouse system. For security reasons, the function can only be executed in the default user profile (with `allow_sleep` enabled). **Syntax** ``` sleep(seconds) ``` **Arguments** - `seconds` β€” The number of seconds to pause the query execution to a maximum of 3 seconds. It can be a floating-point value to specify fractional seconds. [`const UInt*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`const Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) **Returned value** Returns `0`. [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` -- This query will pause for 2 seconds before completing. -- During this time, no results will be returned, and the query will appear to be hanging or unresponsive. SELECT sleep(2); ``` ``` β”Œβ”€sleep(2)─┐ β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ 1 row in set. Elapsed: 2.012 sec. ``` ## sleepEachRow[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#sleepEachRow "Direct link to sleepEachRow") Introduced in: v1.1.0 Pauses the execution of a query for a specified number of seconds for each row in the result set. The `sleepEachRow()` function is primarily used for testing and debugging purposes, similar to the [`sleep()`](https://clickhouse.com/docs/sql-reference/functions/other-functions#sleep) function. It allows you to simulate delays or introduce pauses in the processing of each row, which can be useful in scenarios such as: 1. **Testing**: When testing or benchmarking ClickHouse's performance under specific conditions, you can use `sleepEachRow()` to simulate delays or introduce pauses for each row processed. 2. **Debugging**: If you need to examine the state of the system or the execution of a query for each row processed, you can use `sleepEachRow()` to introduce pauses, allowing you to inspect or collect relevant information. 3. **Simulation**: In some cases, you may want to simulate real-world scenarios where delays or pauses occur for each row processed, such as when dealing with external systems or network latencies. Note Like the `sleep()` function, it's important to use `sleepEachRow()` judiciously and only when necessary, as it can significantly impact the overall performance and responsiveness of your ClickHouse system, especially when dealing with large result sets. **Syntax** ``` sleepEachRow(seconds) ``` **Arguments** - `seconds` β€” The number of seconds to pause the query execution for each row in the result set to a maximum of 3 seconds. It can be a floating-point value to specify fractional seconds. [`const UInt*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`const Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) **Returned value** Returns `0` for each row. [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` -- The output will be delayed, with a 0.5-second pause between each row. SELECT number, sleepEachRow(0.5) FROM system.numbers LIMIT 5; ``` ``` β”Œβ”€number─┬─sleepEachRow(0.5)─┐ β”‚ 0 β”‚ 0 β”‚ β”‚ 1 β”‚ 0 β”‚ β”‚ 2 β”‚ 0 β”‚ β”‚ 3 β”‚ 0 β”‚ β”‚ 4 β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## structureToCapnProtoSchema[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#structureToCapnProtoSchema "Direct link to structureToCapnProtoSchema") Introduced in: v23.8.0 Function that converts ClickHouse table structure to CapnProto format schema **Syntax** ``` structureToCapnProtoSchema(table_structure, message) ``` **Arguments** - None. **Returned value** **Examples** **random** ``` SELECT structureToCapnProtoSchema('s String, x UInt32', 'MessageName') format TSVRaw ``` ``` struct MessageName { s @0 : Data; x @1 : UInt32; } ``` ## structureToProtobufSchema[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#structureToProtobufSchema "Direct link to structureToProtobufSchema") Introduced in: v23.8.0 Converts a ClickHouse table structure to Protobuf format schema. This function takes a ClickHouse table structure definition and converts it into a Protocol Buffers (Protobuf) schema definition in proto3 syntax. This is useful for generating Protobuf schemas that match your ClickHouse table structures for data interchange. **Syntax** ``` structureToProtobufSchema(structure, message_name) ``` **Arguments** - `structure` β€” ClickHouse table structure definition as a string (e.g., 'column1 Type1, column2 Type2'). [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `message_name` β€” Name for the Protobuf message type in the generated schema. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns a Protobuf schema definition in proto3 syntax that corresponds to the input ClickHouse structure. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Converting ClickHouse structure to Protobuf schema** ``` SELECT structureToProtobufSchema('s String, x UInt32', 'MessageName') FORMAT TSVRaw; ``` ``` syntax = "proto3"; message MessageName { bytes s = 1; uint32 x = 2; } ``` ## tcpPort[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#tcpPort "Direct link to tcpPort") Introduced in: v20.12.0 Returns the [native interface](https://clickhouse.com/docs/interfaces/tcp) TCP port number listened to by the server. If executed in the context of a distributed table, this function generates a normal column with values relevant to each shard. Otherwise it produces a constant value. **Syntax** ``` tcpPort() ``` **Arguments** - None. **Returned value** Returns the TCP port number. [`UInt16`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT tcpPort() ``` ``` β”Œβ”€tcpPort()─┐ β”‚ 9000 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## throwIf[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#throwIf "Direct link to throwIf") Introduced in: v1.1.0 Throw an exception if argument x is true. To use the `error_code` argument, configuration parameter `allow_custom_error_code_in_throw` must be enabled. **Syntax** ``` throwIf(x[, message[, error_code]]) ``` **Arguments** - `x` β€” The condition to check. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) - `message` β€” Optional. Custom error message. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `error_code` β€” Optional. Custom error code. [`const Int8/16/32`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Returned value** Returns `0` if the condition is false, throws an exception if the condition is true. [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT throwIf(number = 3, 'Too many') FROM numbers(10); ``` ``` ↙ Progress: 0.00 rows, 0.00 B (0.00 rows/s., 0.00 B/s.) Received exception from server (version 19.14.1): Code: 395. DB::Exception: Received from localhost:9000. DB::Exception: Too many. ``` ## toColumnTypeName[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#toColumnTypeName "Direct link to toColumnTypeName") Introduced in: v1.1.0 Returns the internal name of the data type of the given value. Unlike function [`toTypeName`](https://clickhouse.com/docs/sql-reference/functions/other-functions#toTypeName), the returned data type potentially includes internal wrapper columns like `Const` and `LowCardinality`. **Syntax** ``` toColumnTypeName(value) ``` **Arguments** - `value` β€” Value for which to return the internal data type. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns the internal data type used to represent the value. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT toColumnTypeName(CAST('2025-01-01 01:02:03' AS DateTime)); ``` ``` β”Œβ”€toColumnTypeName(CAST('2025-01-01 01:02:03', 'DateTime'))─┐ β”‚ Const(UInt32) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## toTypeName[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#toTypeName "Direct link to toTypeName") Introduced in: v1.1.0 Returns the type name of the passed argument. If `NULL` is passed, the function returns type `Nullable(Nothing)`, which corresponds to ClickHouse's internal `NULL` representation. **Syntax** ``` toTypeName(x) ``` **Arguments** - `x` β€” A value of arbitrary type. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns the data type name of the input value. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT toTypeName(123) ``` ``` β”Œβ”€toTypeName(123)─┐ β”‚ UInt8 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## transactionID[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#transactionID "Direct link to transactionID") Introduced in: v22.6.0 Experimental feature. [Learn more.](https://clickhouse.com/docs/beta-and-experimental-features#experimental-features) Not supported in ClickHouse Cloud Returns the ID of a transaction. Note This function is part of an experimental feature set. Enable experimental transaction support by adding this setting to your [configuration](https://clickhouse.com/docs/operations/configuration-files): ``` <clickhouse> <allow_experimental_transactions>1</allow_experimental_transactions> </clickhouse> ``` For more information see the page [Transactional (ACID) support](https://clickhouse.com/docs/guides/developer/transactional#transactions-commit-and-rollback). **Syntax** ``` transactionID() ``` **Arguments** - None. **Returned value** Returns a tuple consisting of `start_csn`, `local_tid` and `host_id`. - `start_csn`: Global sequential number, the newest commit timestamp that was seen when this transaction began. - `local_tid`: Local sequential number that is unique for each transaction started by this host within a specific start\_csn. - `host_id`: UUID of the host that has started this transaction. [`Tuple(UInt64, UInt64, UUID)`](https://clickhouse.com/docs/sql-reference/data-types/tuple) **Examples** **Usage example** ``` BEGIN TRANSACTION; SELECT transactionID(); ROLLBACK; ``` ``` β”Œβ”€transactionID()────────────────────────────────┐ β”‚ (32,34,'0ee8b069-f2bb-4748-9eae-069c85b5252b') β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## transactionLatestSnapshot[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#transactionLatestSnapshot "Direct link to transactionLatestSnapshot") Introduced in: v22.6.0 Experimental feature. [Learn more.](https://clickhouse.com/docs/beta-and-experimental-features#experimental-features) Not supported in ClickHouse Cloud Returns the newest snapshot (Commit Sequence Number) of a [transaction](https://clickhouse.com/docs/guides/developer/transactional#transactions-commit-and-rollback) that is available for reading. Note This function is part of an experimental feature set. Enable experimental transaction support by adding this setting to your configuration: ``` <clickhouse> <allow_experimental_transactions>1</allow_experimental_transactions> </clickhouse> ``` For more information see the page [Transactional (ACID) support](https://clickhouse.com/docs/guides/developer/transactional#transactions-commit-and-rollback). **Syntax** ``` transactionLatestSnapshot() ``` **Arguments** - None. **Returned value** Returns the latest snapshot (CSN) of a transaction. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` BEGIN TRANSACTION; SELECT transactionLatestSnapshot(); ROLLBACK; ``` ``` β”Œβ”€transactionLatestSnapshot()─┐ β”‚ 32 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## transactionOldestSnapshot[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#transactionOldestSnapshot "Direct link to transactionOldestSnapshot") Introduced in: v22.6.0 Experimental feature. [Learn more.](https://clickhouse.com/docs/beta-and-experimental-features#experimental-features) Not supported in ClickHouse Cloud Returns the oldest snapshot (Commit Sequence Number) that is visible for some running [transaction](https://clickhouse.com/docs/guides/developer/transactional#transactions-commit-and-rollback). Note This function is part of an experimental feature set. Enable experimental transaction support by adding this setting to your configuration: ``` <clickhouse> <allow_experimental_transactions>1</allow_experimental_transactions> </clickhouse> ``` For more information see the page [Transactional (ACID) support](https://clickhouse.com/docs/guides/developer/transactional#transactions-commit-and-rollback). **Syntax** ``` transactionOldestSnapshot() ``` **Arguments** - None. **Returned value** Returns the oldest snapshot (CSN) of a transaction. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` BEGIN TRANSACTION; SELECT transactionOldestSnapshot(); ROLLBACK; ``` ``` β”Œβ”€transactionOldestSnapshot()─┐ β”‚ 32 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## transform[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#transform "Direct link to transform") Introduced in: v1.1.0 Transforms a value according to the explicitly defined mapping of some elements to other elements. There are two variations of this function: - `transform(x, array_from, array_to, default)` - transforms `x` using mapping arrays with a default value for unmatched elements - `transform(x, array_from, array_to)` - same transformation but returns the original `x` if no match is found The function searches for `x` in `array_from` and returns the corresponding element from `array_to` at the same index. If `x` is not found in `array_from`, it returns either the `default` value (4-parameter version) or the original `x` (3-parameter version). If multiple matching elements exist in `array_from`, it returns the element corresponding to the first match. Requirements: - `array_from` and `array_to` must have the same number of elements - For 4-parameter version: `transform(T, Array(T), Array(U), U) -> U` where `T` and `U` can be different compatible types - For 3-parameter version: `transform(T, Array(T), Array(T)) -> T` where all types must be the same **Syntax** ``` transform(x, array_from, array_to[, default]) ``` **Arguments** - `x` β€” Value to transform. [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) or [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`Date`](https://clickhouse.com/docs/sql-reference/data-types/date) or [`DateTime`](https://clickhouse.com/docs/sql-reference/data-types/datetime) - `array_from` β€” Constant array of values to search for matches. [`Array((U)Int*)`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Array(Decimal)`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Array(Float*)`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Array(String)`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Array(Date)`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Array(DateTime)`](https://clickhouse.com/docs/sql-reference/data-types/array) - `array_to` β€” Constant array of values to return for corresponding matches in `array_from`. [`Array((U)Int*)`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Array(Decimal)`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Array(Float*)`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Array(String)`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Array(Date)`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Array(DateTime)`](https://clickhouse.com/docs/sql-reference/data-types/array) - `default` β€” Optional. Value to return if `x` is not found in `array_from`. If omitted, returns x unchanged. [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) or [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`Date`](https://clickhouse.com/docs/sql-reference/data-types/date) or [`DateTime`](https://clickhouse.com/docs/sql-reference/data-types/datetime) **Returned value** Returns the corresponding value from `array_to` if x matches an element in `array_from`, otherwise returns default (if provided) or x (if default not provided). [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **transform(T, Array(T), Array(U), U) -\> U** ``` SELECT transform(SearchEngineID, [2, 3], ['Yandex', 'Google'], 'Other') AS title, count() AS c FROM test.hits WHERE SearchEngineID != 0 GROUP BY title ORDER BY c DESC ``` ``` β”Œβ”€title─────┬──────c─┐ β”‚ Yandex β”‚ 498635 β”‚ β”‚ Google β”‚ 229872 β”‚ β”‚ Other β”‚ 104472 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **transform(T, Array(T), Array(T)) -\> T** ``` SELECT transform(domain(Referer), ['yandex.ru', 'google.ru', 'vkontakte.ru'], ['www.yandex', 'example.com', 'vk.com']) AS s, count() AS c FROM test.hits GROUP BY domain(Referer) ORDER BY count() DESC LIMIT 10 ``` ``` β”Œβ”€s──────────────┬───────c─┐ β”‚ β”‚ 2906259 β”‚ β”‚ www.yandex β”‚ 867767 β”‚ β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ.ru β”‚ 313599 β”‚ β”‚ mail.yandex.ru β”‚ 107147 β”‚ β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ.ru β”‚ 100355 β”‚ β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ.ru β”‚ 65040 β”‚ β”‚ news.yandex.ru β”‚ 64515 β”‚ β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ.net β”‚ 59141 β”‚ β”‚ example.com β”‚ 57316 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## uniqThetaIntersect[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#uniqThetaIntersect "Direct link to uniqThetaIntersect") Introduced in: v22.9.0 Two uniqThetaSketch objects to do intersect calculation(set operation ∩), the result is a new uniqThetaSketch. **Syntax** ``` uniqThetaIntersect(uniqThetaSketch,uniqThetaSketch) ``` **Arguments** - `uniqThetaSketch` β€” uniqThetaSketch object. [`Tuple`](https://clickhouse.com/docs/sql-reference/data-types/tuple) or [`Array`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Date`](https://clickhouse.com/docs/sql-reference/data-types/date) or [`DateTime`](https://clickhouse.com/docs/sql-reference/data-types/datetime) or [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) or [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) **Returned value** A new uniqThetaSketch containing the intersect result. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT finalizeAggregation(uniqThetaIntersect(a, b)) AS a_intersect_b, finalizeAggregation(a) AS a_cardinality, finalizeAggregation(b) AS b_cardinality FROM (SELECT arrayReduce('uniqThetaState', [1, 2]) AS a, arrayReduce('uniqThetaState', [2, 3, 4]) AS b); ``` ``` β”Œβ”€a_intersect_b─┬─a_cardinality─┬─b_cardinality─┐ β”‚ 1 β”‚ 2 β”‚ 3 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## uniqThetaNot[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#uniqThetaNot "Direct link to uniqThetaNot") Introduced in: v22.9.0 Two uniqThetaSketch objects to do a\_not\_b calculation(set operation Γ—), the result is a new uniqThetaSketch. **Syntax** ``` uniqThetaNot(uniqThetaSketch,uniqThetaSketch) ``` **Arguments** - `uniqThetaSketch` β€” uniqThetaSketch object. [`Tuple`](https://clickhouse.com/docs/sql-reference/data-types/tuple) or [`Array`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Date`](https://clickhouse.com/docs/sql-reference/data-types/date) or [`DateTime`](https://clickhouse.com/docs/sql-reference/data-types/datetime) or [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) or [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) **Returned value** Returns a new uniqThetaSketch containing the a\_not\_b result. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT finalizeAggregation(uniqThetaNot(a, b)) AS a_not_b, finalizeAggregation(a) AS a_cardinality, finalizeAggregation(b) AS b_cardinality FROM (SELECT arrayReduce('uniqThetaState', [2, 3, 4]) AS a, arrayReduce('uniqThetaState', [1, 2]) AS b); ``` ``` β”Œβ”€a_not_b─┬─a_cardinality─┬─b_cardinality─┐ β”‚ 2 β”‚ 3 β”‚ 2 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## uniqThetaUnion[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#uniqThetaUnion "Direct link to uniqThetaUnion") Introduced in: v22.9.0 Two uniqThetaSketch objects to do union calculation(set operation βˆͺ), the result is a new uniqThetaSketch. **Syntax** ``` uniqThetaUnion(uniqThetaSketch,uniqThetaSketch) ``` **Arguments** - `uniqThetaSketch` β€” uniqThetaSketch object. [`Tuple`](https://clickhouse.com/docs/sql-reference/data-types/tuple) or [`Array`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Date`](https://clickhouse.com/docs/sql-reference/data-types/date) or [`DateTime`](https://clickhouse.com/docs/sql-reference/data-types/datetime) or [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) or [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) **Returned value** Returns a new uniqThetaSketch containing the union result. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT finalizeAggregation(uniqThetaUnion(a, b)) AS a_union_b, finalizeAggregation(a) AS a_cardinality, finalizeAggregation(b) AS b_cardinality FROM (SELECT arrayReduce('uniqThetaState', [1, 2]) AS a, arrayReduce('uniqThetaState', [2, 3, 4]) AS b); ``` ``` β”Œβ”€a_union_b─┬─a_cardinality─┬─b_cardinality─┐ β”‚ 4 β”‚ 2 β”‚ 3 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## uptime[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#uptime "Direct link to uptime") Introduced in: v1.1.0 Returns the server's uptime in seconds. If executed in the context of a distributed table, this function generates a normal column with values relevant to each shard. Otherwise it produces a constant value. **Syntax** ``` uptime() ``` **Arguments** - None. **Returned value** Returns the server uptime in seconds. [`UInt32`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT uptime() AS Uptime ``` ``` β”Œβ”€Uptime─┐ β”‚ 55867 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## variantElement[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#variantElement "Direct link to variantElement") Introduced in: v25.2.0 Extracts a column with specified type from a `Variant` column. **Syntax** ``` variantElement(variant, type_name[, default_value]) ``` **Arguments** - `variant` β€” Variant column. [`Variant`](https://clickhouse.com/docs/sql-reference/data-types/variant) - `type_name` β€” The name of the variant type to extract. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `default_value` β€” The default value that will be used if variant doesn't have variant with specified type. Can be any type. Optional. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns a column with the specified variant type extracted from the Variant column. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **Usage example** ``` CREATE TABLE test (v Variant(UInt64, String, Array(UInt64))) ENGINE = Memory; INSERT INTO test VALUES (NULL), (42), ('Hello, World!'), ([1, 2, 3]); SELECT v, variantElement(v, 'String'), variantElement(v, 'UInt64'), variantElement(v, 'Array(UInt64)') FROM test; ``` ``` β”Œβ”€v─────────────┬─variantElement(v, 'String')─┬─variantElement(v, 'UInt64')─┬─variantElement(v, 'Array(UInt64)')─┐ β”‚ ᴺᡁᴸᴸ β”‚ ᴺᡁᴸᴸ β”‚ ᴺᡁᴸᴸ β”‚ [] β”‚ β”‚ 42 β”‚ ᴺᡁᴸᴸ β”‚ 42 β”‚ [] β”‚ β”‚ Hello, World! β”‚ Hello, World! β”‚ ᴺᡁᴸᴸ β”‚ [] β”‚ β”‚ [1,2,3] β”‚ ᴺᡁᴸᴸ β”‚ ᴺᡁᴸᴸ β”‚ [1,2,3] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## variantType[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#variantType "Direct link to variantType") Introduced in: v24.2.0 Returns the variant type name for each row of `Variant` column. If row contains NULL, it returns 'None' for it. **Syntax** ``` variantType(variant) ``` **Arguments** - `variant` β€” Variant column. [`Variant`](https://clickhouse.com/docs/sql-reference/data-types/variant) **Returned value** Returns an Enum column with variant type name for each row. [`Enum`](https://clickhouse.com/docs/sql-reference/data-types/enum) **Examples** **Usage example** ``` CREATE TABLE test (v Variant(UInt64, String, Array(UInt64))) ENGINE = Memory; INSERT INTO test VALUES (NULL), (42), ('Hello, World!'), ([1, 2, 3]); SELECT variantType(v) FROM test; ``` ``` β”Œβ”€variantType(v)─┐ β”‚ None β”‚ β”‚ UInt64 β”‚ β”‚ String β”‚ β”‚ Array(UInt64) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## version[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#version "Direct link to version") Introduced in: v1.1.0 Returns the current version of ClickHouse as a string in the form: `major_version.minor_version.patch_version.number_of_commits_since_the_previous_stable_release`. If executed in the context of a distributed table, this function generates a normal column with values relevant to each shard. Otherwise, it produces a constant value. **Syntax** ``` version() ``` **Arguments** - None. **Returned value** Returns the current version of ClickHouse. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT version() ``` ``` β”Œβ”€version()─┐ β”‚ 24.2.1.1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## visibleWidth[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#visibleWidth "Direct link to visibleWidth") Introduced in: v1.1.0 Calculates the approximate width when outputting values to the console in text format (tab-separated). This function is used by the system to implement Pretty formats. `NULL` is represented as a string corresponding to `NULL` in Pretty formats. **Syntax** ``` visibleWidth(x) ``` **Arguments** - `x` β€” A value of any data type. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns the approximate width of the value when displayed in text format. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Calculate visible width of NULL** ``` SELECT visibleWidth(NULL) ``` ``` β”Œβ”€visibleWidth(NULL)─┐ β”‚ 4 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## zookeeperSessionUptime[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#zookeeperSessionUptime "Direct link to zookeeperSessionUptime") Introduced in: v21.11.0 Returns the uptime of the current ZooKeeper session in seconds. **Syntax** ``` zookeeperSessionUptime() ``` **Arguments** - None. **Returned value** Returns the uptime of the current ZooKeeper session in seconds. [`UInt32`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT zookeeperSessionUptime(); ``` ``` β”Œβ”€zookeeperSessionUptime()─┐ β”‚ 286 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` [Previous NumericIndexedVector](https://clickhouse.com/docs/sql-reference/functions/numeric-indexed-vector-functions) [Next Random number](https://clickhouse.com/docs/sql-reference/functions/random-functions) - [FQDN](https://clickhouse.com/docs/sql-reference/functions/other-functions#FQDN) - [MACNumToString](https://clickhouse.com/docs/sql-reference/functions/other-functions#MACNumToString) - [MACStringToNum](https://clickhouse.com/docs/sql-reference/functions/other-functions#MACStringToNum) - [MACStringToOUI](https://clickhouse.com/docs/sql-reference/functions/other-functions#MACStringToOUI) - [authenticatedUser](https://clickhouse.com/docs/sql-reference/functions/other-functions#authenticatedUser) - [bar](https://clickhouse.com/docs/sql-reference/functions/other-functions#bar) - [blockNumber](https://clickhouse.com/docs/sql-reference/functions/other-functions#blockNumber) - [blockSerializedSize](https://clickhouse.com/docs/sql-reference/functions/other-functions#blockSerializedSize) - [blockSize](https://clickhouse.com/docs/sql-reference/functions/other-functions#blockSize) - [buildId](https://clickhouse.com/docs/sql-reference/functions/other-functions#buildId) - [byteSize](https://clickhouse.com/docs/sql-reference/functions/other-functions#byteSize) - [catboostEvaluate](https://clickhouse.com/docs/sql-reference/functions/other-functions#catboostEvaluate) - [colorOKLABToSRGB](https://clickhouse.com/docs/sql-reference/functions/other-functions#colorOKLABToSRGB) - [colorOKLCHToSRGB](https://clickhouse.com/docs/sql-reference/functions/other-functions#colorOKLCHToSRGB) - [colorSRGBToOKLAB](https://clickhouse.com/docs/sql-reference/functions/other-functions#colorSRGBToOKLAB) - [colorSRGBToOKLCH](https://clickhouse.com/docs/sql-reference/functions/other-functions#colorSRGBToOKLCH) - [connectionId](https://clickhouse.com/docs/sql-reference/functions/other-functions#connectionId) - [countDigits](https://clickhouse.com/docs/sql-reference/functions/other-functions#countDigits) - [currentDatabase](https://clickhouse.com/docs/sql-reference/functions/other-functions#currentDatabase) - [currentProfiles](https://clickhouse.com/docs/sql-reference/functions/other-functions#currentProfiles) - [currentQueryID](https://clickhouse.com/docs/sql-reference/functions/other-functions#currentQueryID) - [currentRoles](https://clickhouse.com/docs/sql-reference/functions/other-functions#currentRoles) - [currentSchemas](https://clickhouse.com/docs/sql-reference/functions/other-functions#currentSchemas) - [currentUser](https://clickhouse.com/docs/sql-reference/functions/other-functions#currentUser) - [defaultProfiles](https://clickhouse.com/docs/sql-reference/functions/other-functions#defaultProfiles) - [defaultRoles](https://clickhouse.com/docs/sql-reference/functions/other-functions#defaultRoles) - [defaultValueOfArgumentType](https://clickhouse.com/docs/sql-reference/functions/other-functions#defaultValueOfArgumentType) - [defaultValueOfTypeName](https://clickhouse.com/docs/sql-reference/functions/other-functions#defaultValueOfTypeName) - [displayName](https://clickhouse.com/docs/sql-reference/functions/other-functions#displayName) - [dumpColumnStructure](https://clickhouse.com/docs/sql-reference/functions/other-functions#dumpColumnStructure) - [enabledProfiles](https://clickhouse.com/docs/sql-reference/functions/other-functions#enabledProfiles) - [enabledRoles](https://clickhouse.com/docs/sql-reference/functions/other-functions#enabledRoles) - [errorCodeToName](https://clickhouse.com/docs/sql-reference/functions/other-functions#errorCodeToName) - [file](https://clickhouse.com/docs/sql-reference/functions/other-functions#file) - [filesystemAvailable](https://clickhouse.com/docs/sql-reference/functions/other-functions#filesystemAvailable) - [filesystemCapacity](https://clickhouse.com/docs/sql-reference/functions/other-functions#filesystemCapacity) - [filesystemUnreserved](https://clickhouse.com/docs/sql-reference/functions/other-functions#filesystemUnreserved) - [finalizeAggregation](https://clickhouse.com/docs/sql-reference/functions/other-functions#finalizeAggregation) - [flipCoordinates](https://clickhouse.com/docs/sql-reference/functions/other-functions#flipCoordinates) - [formatQuery](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatQuery) - [formatQueryOrNull](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatQueryOrNull) - [formatQuerySingleLine](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatQuerySingleLine) - [formatQuerySingleLineOrNull](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatQuerySingleLineOrNull) - [formatReadableDecimalSize](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatReadableDecimalSize) - [formatReadableQuantity](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatReadableQuantity) - [formatReadableSize](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatReadableSize) - [formatReadableTimeDelta](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatReadableTimeDelta) - [fuzzQuery](https://clickhouse.com/docs/sql-reference/functions/other-functions#fuzzQuery) - [generateRandomStructure](https://clickhouse.com/docs/sql-reference/functions/other-functions#generateRandomStructure) - [generateSerialID](https://clickhouse.com/docs/sql-reference/functions/other-functions#generateSerialID) - [getClientHTTPHeader](https://clickhouse.com/docs/sql-reference/functions/other-functions#getClientHTTPHeader) - [getMacro](https://clickhouse.com/docs/sql-reference/functions/other-functions#getMacro) - [getMaxTableNameLengthForDatabase](https://clickhouse.com/docs/sql-reference/functions/other-functions#getMaxTableNameLengthForDatabase) - [getMergeTreeSetting](https://clickhouse.com/docs/sql-reference/functions/other-functions#getMergeTreeSetting) - [getOSKernelVersion](https://clickhouse.com/docs/sql-reference/functions/other-functions#getOSKernelVersion) - [getServerPort](https://clickhouse.com/docs/sql-reference/functions/other-functions#getServerPort) - [getServerSetting](https://clickhouse.com/docs/sql-reference/functions/other-functions#getServerSetting) - [getSetting](https://clickhouse.com/docs/sql-reference/functions/other-functions#getSetting) - [getSettingOrDefault](https://clickhouse.com/docs/sql-reference/functions/other-functions#getSettingOrDefault) - [getSizeOfEnumType](https://clickhouse.com/docs/sql-reference/functions/other-functions#getSizeOfEnumType) - [getSubcolumn](https://clickhouse.com/docs/sql-reference/functions/other-functions#getSubcolumn) - [getTypeSerializationStreams](https://clickhouse.com/docs/sql-reference/functions/other-functions#getTypeSerializationStreams) - [globalVariable](https://clickhouse.com/docs/sql-reference/functions/other-functions#globalVariable) - [hasColumnInTable](https://clickhouse.com/docs/sql-reference/functions/other-functions#hasColumnInTable) - [hasThreadFuzzer](https://clickhouse.com/docs/sql-reference/functions/other-functions#hasThreadFuzzer) - [hostName](https://clickhouse.com/docs/sql-reference/functions/other-functions#hostName) - [icebergBucket](https://clickhouse.com/docs/sql-reference/functions/other-functions#icebergBucket) - [icebergTruncate](https://clickhouse.com/docs/sql-reference/functions/other-functions#icebergTruncate) - [identity](https://clickhouse.com/docs/sql-reference/functions/other-functions#identity) - [ignore](https://clickhouse.com/docs/sql-reference/functions/other-functions#ignore) - [indexHint](https://clickhouse.com/docs/sql-reference/functions/other-functions#indexHint) - [initialQueryID](https://clickhouse.com/docs/sql-reference/functions/other-functions#initialQueryID) - [initialQueryStartTime](https://clickhouse.com/docs/sql-reference/functions/other-functions#initialQueryStartTime) - [initializeAggregation](https://clickhouse.com/docs/sql-reference/functions/other-functions#initializeAggregation) - [isConstant](https://clickhouse.com/docs/sql-reference/functions/other-functions#isConstant) - [isDecimalOverflow](https://clickhouse.com/docs/sql-reference/functions/other-functions#isDecimalOverflow) - [joinGet](https://clickhouse.com/docs/sql-reference/functions/other-functions#joinGet) - [joinGetOrNull](https://clickhouse.com/docs/sql-reference/functions/other-functions#joinGetOrNull) - [lowCardinalityIndices](https://clickhouse.com/docs/sql-reference/functions/other-functions#lowCardinalityIndices) - [lowCardinalityKeys](https://clickhouse.com/docs/sql-reference/functions/other-functions#lowCardinalityKeys) - [materialize](https://clickhouse.com/docs/sql-reference/functions/other-functions#materialize) - [minSampleSizeContinuous](https://clickhouse.com/docs/sql-reference/functions/other-functions#minSampleSizeContinuous) - [minSampleSizeConversion](https://clickhouse.com/docs/sql-reference/functions/other-functions#minSampleSizeConversion) - [neighbor](https://clickhouse.com/docs/sql-reference/functions/other-functions#neighbor) - [normalizeQuery](https://clickhouse.com/docs/sql-reference/functions/other-functions#normalizeQuery) - [normalizeQueryKeepNames](https://clickhouse.com/docs/sql-reference/functions/other-functions#normalizeQueryKeepNames) - [normalizedQueryHash](https://clickhouse.com/docs/sql-reference/functions/other-functions#normalizedQueryHash) - [normalizedQueryHashKeepNames](https://clickhouse.com/docs/sql-reference/functions/other-functions#normalizedQueryHashKeepNames) - [parseReadableSize](https://clickhouse.com/docs/sql-reference/functions/other-functions#parseReadableSize) - [parseReadableSizeOrNull](https://clickhouse.com/docs/sql-reference/functions/other-functions#parseReadableSizeOrNull) - [parseReadableSizeOrZero](https://clickhouse.com/docs/sql-reference/functions/other-functions#parseReadableSizeOrZero) - [parseTimeDelta](https://clickhouse.com/docs/sql-reference/functions/other-functions#parseTimeDelta) - [partitionId](https://clickhouse.com/docs/sql-reference/functions/other-functions#partitionId) - [queryID](https://clickhouse.com/docs/sql-reference/functions/other-functions#queryID) - [revision](https://clickhouse.com/docs/sql-reference/functions/other-functions#revision) - [rowNumberInAllBlocks](https://clickhouse.com/docs/sql-reference/functions/other-functions#rowNumberInAllBlocks) - [rowNumberInBlock](https://clickhouse.com/docs/sql-reference/functions/other-functions#rowNumberInBlock) - [runningAccumulate](https://clickhouse.com/docs/sql-reference/functions/other-functions#runningAccumulate) - [runningConcurrency](https://clickhouse.com/docs/sql-reference/functions/other-functions#runningConcurrency) - [runningDifference](https://clickhouse.com/docs/sql-reference/functions/other-functions#runningDifference) - [runningDifferenceStartingWithFirstValue](https://clickhouse.com/docs/sql-reference/functions/other-functions#runningDifferenceStartingWithFirstValue) - [serverUUID](https://clickhouse.com/docs/sql-reference/functions/other-functions#serverUUID) - [shardCount](https://clickhouse.com/docs/sql-reference/functions/other-functions#shardCount) - [shardNum](https://clickhouse.com/docs/sql-reference/functions/other-functions#shardNum) - [showCertificate](https://clickhouse.com/docs/sql-reference/functions/other-functions#showCertificate) - [sleep](https://clickhouse.com/docs/sql-reference/functions/other-functions#sleep) - [sleepEachRow](https://clickhouse.com/docs/sql-reference/functions/other-functions#sleepEachRow) - [structureToCapnProtoSchema](https://clickhouse.com/docs/sql-reference/functions/other-functions#structureToCapnProtoSchema) - [structureToProtobufSchema](https://clickhouse.com/docs/sql-reference/functions/other-functions#structureToProtobufSchema) - [tcpPort](https://clickhouse.com/docs/sql-reference/functions/other-functions#tcpPort) - [throwIf](https://clickhouse.com/docs/sql-reference/functions/other-functions#throwIf) - [toColumnTypeName](https://clickhouse.com/docs/sql-reference/functions/other-functions#toColumnTypeName) - [toTypeName](https://clickhouse.com/docs/sql-reference/functions/other-functions#toTypeName) - [transactionID](https://clickhouse.com/docs/sql-reference/functions/other-functions#transactionID) - [transactionLatestSnapshot](https://clickhouse.com/docs/sql-reference/functions/other-functions#transactionLatestSnapshot) - [transactionOldestSnapshot](https://clickhouse.com/docs/sql-reference/functions/other-functions#transactionOldestSnapshot) - [transform](https://clickhouse.com/docs/sql-reference/functions/other-functions#transform) - [uniqThetaIntersect](https://clickhouse.com/docs/sql-reference/functions/other-functions#uniqThetaIntersect) - [uniqThetaNot](https://clickhouse.com/docs/sql-reference/functions/other-functions#uniqThetaNot) - [uniqThetaUnion](https://clickhouse.com/docs/sql-reference/functions/other-functions#uniqThetaUnion) - [uptime](https://clickhouse.com/docs/sql-reference/functions/other-functions#uptime) - [variantElement](https://clickhouse.com/docs/sql-reference/functions/other-functions#variantElement) - [variantType](https://clickhouse.com/docs/sql-reference/functions/other-functions#variantType) - [version](https://clickhouse.com/docs/sql-reference/functions/other-functions#version) - [visibleWidth](https://clickhouse.com/docs/sql-reference/functions/other-functions#visibleWidth) - [zookeeperSessionUptime](https://clickhouse.com/docs/sql-reference/functions/other-functions#zookeeperSessionUptime) Was this page helpful? ###### Try ClickHouse Cloud for FREE Separation of storage and compute, automatic scaling, built-in SQL console, and lots more. \$300 in free credits when signing up. [Try it for Free](https://console.clickhouse.cloud/signUp?loc=doc-card-banner&glxid=6adfcdfe-d44a-48bb-a003-4ea1abaf38ea&pagePath=%2Fdocs%2Fsql-reference%2Ffunctions%2Fother-functions&origPath=%2Fdocs%2Fsql-reference%2Ffunctions%2Fother-functions&utm_ga=GA1.1.745291207.1776676661) Β© 2016–2026 ClickHouse, Inc. [Trademark](https://clickhouse.com/legal/trademark-policy)Β·[Privacy](https://clickhouse.com/legal/privacy-policy)Β·[Security](https://trust.clickhouse.com/)Β·[Terms of Service](https://clickhouse.com/legal/agreements/terms-of-service) ![](https://static.scarf.sh/a.png?x-pxid=e6377503-591b-4886-9398-e69c7fee0b91) Β© 2016–2026 ClickHouse, Inc. [Trademark](https://clickhouse.com/legal/trademark-policy)Β·[Privacy](https://clickhouse.com/legal/privacy-policy)Β·[Security](https://trust.clickhouse.com/)Β·[Terms of Service](https://clickhouse.com/legal/agreements/terms-of-service) ![](https://static.scarf.sh/a.png?x-pxid=e6377503-591b-4886-9398-e69c7fee0b91) [![ClickHouse](https://clickhouse.com/docs/img/ch_logo_docs.svg)](https://clickhouse.com/) EN - Get startedβ–Ό - Cloudβ–Ό - Manage dataβ–Ό - Server adminβ–Ό - Referenceβ–Ό - Integrationsβ–Ό - ClickStackβ–Ό - chDBβ–Ό - Aboutβ–Ό [![ClickHouse](https://clickhouse.com/docs/img/ch_logo_docs.svg)](https://clickhouse.com/) EN main-menu - Introductionβ–Ό - [Syntax](https://clickhouse.com/docs/sql-reference/syntax) - [Input and Output Formats](https://clickhouse.com/docs/sql-reference/formats) - Data typesβ–Ό - Statementsβ–Ό - Operatorsβ–Ό - Enginesβ–Ό - Functionsβ–Ό - Regular functionsβ–Ό - [Overview](https://clickhouse.com/docs/sql-reference/functions/overview) - [AI](https://clickhouse.com/docs/sql-reference/functions/ai-functions) - [Arithmetic](https://clickhouse.com/docs/sql-reference/functions/arithmetic-functions) - [Arrays](https://clickhouse.com/docs/sql-reference/functions/array-functions) - [arrayJoin](https://clickhouse.com/docs/sql-reference/functions/array-join) - [Bit](https://clickhouse.com/docs/sql-reference/functions/bit-functions) - [Bitmap](https://clickhouse.com/docs/sql-reference/functions/bitmap-functions) - [Comparison](https://clickhouse.com/docs/sql-reference/functions/comparison-functions) - [Conditional](https://clickhouse.com/docs/sql-reference/functions/conditional-functions) - [Dates and time](https://clickhouse.com/docs/sql-reference/functions/date-time-functions) - [Distance](https://clickhouse.com/docs/sql-reference/functions/distance-functions) - [Embedded dictionary](https://clickhouse.com/docs/sql-reference/functions/ym-dict-functions) - [Encoding](https://clickhouse.com/docs/sql-reference/functions/encoding-functions) - [Encryption](https://clickhouse.com/docs/sql-reference/functions/encryption-functions) - [Dictionaries](https://clickhouse.com/docs/sql-reference/functions/ext-dict-functions) - [Files](https://clickhouse.com/docs/sql-reference/functions/files) - [Financial](https://clickhouse.com/docs/sql-reference/functions/financial-functions) - [Nullable](https://clickhouse.com/docs/sql-reference/functions/functions-for-nulls) - Geometryβ–Ό - [Hash](https://clickhouse.com/docs/sql-reference/functions/hash-functions) - [IN Operator](https://clickhouse.com/docs/sql-reference/functions/in-functions) - [Introspection](https://clickhouse.com/docs/sql-reference/functions/introspection) - [IP Addresses](https://clickhouse.com/docs/sql-reference/functions/ip-address-functions) - [JSON](https://clickhouse.com/docs/sql-reference/functions/json-functions) - [Logical](https://clickhouse.com/docs/sql-reference/functions/logical-functions) - [Machine Learning](https://clickhouse.com/docs/sql-reference/functions/machine-learning-functions) - [Mathematical](https://clickhouse.com/docs/sql-reference/functions/math-functions) - [NLP](https://clickhouse.com/docs/sql-reference/functions/nlp-functions) - [NumericIndexedVector](https://clickhouse.com/docs/sql-reference/functions/numeric-indexed-vector-functions) - [Other](https://clickhouse.com/docs/sql-reference/functions/other-functions) - [Random number](https://clickhouse.com/docs/sql-reference/functions/random-functions) - [Rounding](https://clickhouse.com/docs/sql-reference/functions/rounding-functions) - [String splitting](https://clickhouse.com/docs/sql-reference/functions/splitting-merging-functions) - [String](https://clickhouse.com/docs/sql-reference/functions/string-functions) - [String replacement](https://clickhouse.com/docs/sql-reference/functions/string-replace-functions) - [String search](https://clickhouse.com/docs/sql-reference/functions/string-search-functions) - [TimeSeries](https://clickhouse.com/docs/sql-reference/functions/time-series-functions) - [Time window](https://clickhouse.com/docs/sql-reference/functions/time-window-functions) - [Tuples](https://clickhouse.com/docs/sql-reference/functions/tuple-functions) - [Maps](https://clickhouse.com/docs/sql-reference/functions/tuple-map-functions) - [Type conversion](https://clickhouse.com/docs/sql-reference/functions/type-conversion-functions) - [UDF](https://clickhouse.com/docs/sql-reference/functions/udf) - [ULIDs](https://clickhouse.com/docs/sql-reference/functions/ulid-functions) - [uniqTheta](https://clickhouse.com/docs/sql-reference/functions/uniqtheta-functions) - [URLs](https://clickhouse.com/docs/sql-reference/functions/url-functions) - [UUIDs](https://clickhouse.com/docs/sql-reference/functions/uuid-functions) - [WebAssembly UDFs](https://clickhouse.com/docs/sql-reference/functions/wasm_udf) - Aggregate functionsβ–Ό - Table functionsβ–Ό - Window functionsβ–Ό - Formatsβ–Ό - [Data Lakes](https://clickhouse.com/docs/sql-reference/datalakes)
Readable Markdown
Note The function documentation below is generated from the `system.functions` system table. ## FQDN[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#FQDN "Direct link to FQDN") Introduced in: v20.1.0 Returns the fully qualified domain name of the ClickHouse server. **Syntax** ``` FQDN() ``` **Aliases**: `fullHostName` **Arguments** - None. **Returned value** Returns the fully qualified domain name of the ClickHouse server. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** Query ``` SELECT fqdn() ``` Response ``` β”Œβ”€FQDN()──────────────────────────┐ β”‚ clickhouse.us-east-2.internal β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## MACNumToString[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#MACNumToString "Direct link to MACNumToString") Introduced in: v1.1.0 Interprets a [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) number as a MAC address in big endian format. Returns the corresponding MAC address in format `AA:BB:CC:DD:EE:FF` (colon-separated numbers in hexadecimal form) as string. **Syntax** ``` MACNumToString(num) ``` **Arguments** - `num` β€” UInt64 number. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Returned value** Returns a MAC address in format AA:BB:CC:DD:EE:FF. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** Query ``` SELECT MACNumToString(149809441867716) AS mac_address; ``` Response ``` β”Œβ”€mac_address───────┐ β”‚ 88:00:11:22:33:44 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## MACStringToNum[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#MACStringToNum "Direct link to MACStringToNum") Introduced in: v1.1.0 The inverse function of MACNumToString. If the MAC address has an invalid format, it returns 0. **Syntax** ``` MACStringToNum(s) ``` **Arguments** - `s` β€” MAC address string. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns a UInt64 number. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** Query ``` SELECT MACStringToNum('01:02:03:04:05:06') AS mac_numeric; ``` Response ``` 1108152157446 ``` ## MACStringToOUI[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#MACStringToOUI "Direct link to MACStringToOUI") Introduced in: v1.1.0 Given a MAC address in format AA:BB:CC:DD:EE:FF (colon-separated numbers in hexadecimal form), returns the first three octets as a UInt64 number. If the MAC address has an invalid format, it returns 0. **Syntax** ``` MACStringToOUI(s) ``` **Arguments** - `s` β€” MAC address string. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** First three octets as UInt64 number. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** Query ``` SELECT MACStringToOUI('00:50:56:12:34:56') AS oui; ``` Response ``` 20566 ``` ## authenticatedUser[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#authenticatedUser "Direct link to authenticatedUser") Introduced in: v25.11.0 If the session user has been switched using the EXECUTE AS command, this function returns the name of the original user that was used for authentication and creating the session. Alias: authUser() **Syntax** ``` authenticatedUser() ``` **Aliases**: `authUser` **Arguments** - None. **Returned value** The name of the authenticated user. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** Query ``` EXECUTE as u1; SELECT currentUser(), authenticatedUser(); ``` Response ``` β”Œβ”€currentUser()─┬─authenticatedUser()─┐ β”‚ u1 β”‚ default β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## bar[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#bar "Direct link to bar") Introduced in: v1.1.0 Builds a bar chart. Draws a band with width proportional to (x - min) and equal to width characters when x = max. The band is drawn with accuracy to one eighth of a symbol. **Syntax** ``` bar(x, min, max[, width]) ``` **Arguments** - `x` β€” Size to display. [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) or [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) - `min` β€” The minimum value. [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) or [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) - `max` β€” The maximum value. [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) or [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) - `width` β€” Optional. The width of the bar in characters. The default is `80`. [`const (U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`const Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) or [`const Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) **Returned value** Returns a unicode-art bar string. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** Query ``` SELECT toHour(EventTime) AS h, count() AS c, bar(c, 0, 600000, 20) AS bar FROM test.hits GROUP BY h ORDER BY h ASC ``` Response ``` β”Œβ”€β”€h─┬──────c─┬─bar────────────────┐ β”‚ 0 β”‚ 292907 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‹ β”‚ β”‚ 1 β”‚ 180563 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β”‚ β”‚ 2 β”‚ 114861 β”‚ β–ˆβ–ˆβ–ˆβ–‹ β”‚ β”‚ 3 β”‚ 85069 β”‚ β–ˆβ–ˆβ–‹ β”‚ β”‚ 4 β”‚ 68543 β”‚ β–ˆβ–ˆβ–Ž β”‚ β”‚ 5 β”‚ 78116 β”‚ β–ˆβ–ˆβ–Œ β”‚ β”‚ 6 β”‚ 113474 β”‚ β–ˆβ–ˆβ–ˆβ–‹ β”‚ β”‚ 7 β”‚ 170678 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‹ β”‚ β”‚ 8 β”‚ 278380 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Ž β”‚ β”‚ 9 β”‚ 391053 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β”‚ β”‚ 10 β”‚ 457681 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Ž β”‚ β”‚ 11 β”‚ 493667 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ– β”‚ β”‚ 12 β”‚ 509641 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Š β”‚ β”‚ 13 β”‚ 522947 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ– β”‚ β”‚ 14 β”‚ 539954 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Š β”‚ β”‚ 15 β”‚ 528460 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Œ β”‚ β”‚ 16 β”‚ 539201 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Š β”‚ β”‚ 17 β”‚ 523539 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ– β”‚ β”‚ 18 β”‚ 506467 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Š β”‚ β”‚ 19 β”‚ 520915 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Ž β”‚ β”‚ 20 β”‚ 521665 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ– β”‚ β”‚ 21 β”‚ 542078 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β”‚ β”‚ 22 β”‚ 493642 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ– β”‚ β”‚ 23 β”‚ 400397 β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Ž β”‚ β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## blockNumber[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#blockNumber "Direct link to blockNumber") Introduced in: v1.1.0 Returns a monotonically increasing sequence number of the [block](https://clickhouse.com/docs/development/architecture#block) containing the row. The returned block number is updated on a best-effort basis, i.e. it may not be fully accurate. **Syntax** ``` blockNumber() ``` **Arguments** - None. **Returned value** Sequence number of the data block where the row is located. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Basic usage** Query ``` SELECT blockNumber() FROM ( SELECT * FROM system.numbers LIMIT 10 ) SETTINGS max_block_size = 2 ``` Response ``` β”Œβ”€blockNumber()─┐ β”‚ 7 β”‚ β”‚ 7 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€blockNumber()─┐ β”‚ 8 β”‚ β”‚ 8 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€blockNumber()─┐ β”‚ 9 β”‚ β”‚ 9 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€blockNumber()─┐ β”‚ 10 β”‚ β”‚ 10 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€blockNumber()─┐ β”‚ 11 β”‚ β”‚ 11 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## blockSerializedSize[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#blockSerializedSize "Direct link to blockSerializedSize") Introduced in: v20.3.0 Returns the uncompressed size in bytes of a block of values on disk. **Syntax** ``` blockSerializedSize(x1[, x2[, ...]]) ``` **Arguments** - `x1[, x2, ...]` β€” Any number of values for which to get the uncompressed size of the block. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns the number of bytes that will be written to disk for a block of values without compression. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** Query ``` SELECT blockSerializedSize(maxState(1)) AS x; ``` Response ``` β”Œβ”€x─┐ β”‚ 2 β”‚ β””β”€β”€β”€β”˜ ``` ## blockSize[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#blockSize "Direct link to blockSize") Introduced in: v1.1.0 In ClickHouse, queries are processed in [blocks](https://clickhouse.com/docs/development/architecture#block) (chunks). This function returns the size (row count) of the block the function is called on. **Syntax** ``` blockSize() ``` **Arguments** - None. **Returned value** Returns the number of rows in the current block. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** Query ``` SELECT blockSize() FROM system.numbers LIMIT 5 ``` Response ``` β”Œβ”€blockSize()─┐ β”‚ 5 β”‚ β”‚ 5 β”‚ β”‚ 5 β”‚ β”‚ 5 β”‚ β”‚ 5 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## buildId[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#buildId "Direct link to buildId") Introduced in: v20.5.0 Returns the build ID generated by a compiler for the running ClickHouse server binary. If executed in the context of a distributed table, this function generates a normal column with values relevant to each shard. Otherwise it produces a constant value. **Syntax** ``` buildId() ``` **Arguments** - None. **Returned value** Returns the build ID. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** Query ``` SELECT buildId() ``` Response ``` β”Œβ”€buildId()────────────────────────────────┐ β”‚ AB668BEF095FAA6BD26537F197AC2AF48A927FB4 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## byteSize[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#byteSize "Direct link to byteSize") Introduced in: v21.1.0 Returns an estimation of the uncompressed byte size of its arguments in memory. For `String` arguments, the function returns the string length + 8 (length). If the function has multiple arguments, the function accumulates their byte sizes. **Syntax** ``` byteSize(arg1[, arg2, ...]) ``` **Arguments** - `arg1[, arg2, ...]` β€” Values of any data type for which to estimate the uncompressed byte size. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns an estimation of the byte size of the arguments in memory. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** Query ``` SELECT byteSize('string') ``` Response ``` β”Œβ”€byteSize('string')─┐ β”‚ 15 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Multiple arguments** Query ``` SELECT byteSize(NULL, 1, 0.3, '') ``` Response ``` β”Œβ”€byteSize(NULL, 1, 0.3, '')─┐ β”‚ 19 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## catboostEvaluate[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#catboostEvaluate "Direct link to catboostEvaluate") Introduced in: v22.9.0 Evaluate an external catboost model. [CatBoost](https://catboost.ai/) is an open-source gradient boosting library developed by Yandex for machine learning. Accepts a path to a catboost model and model arguments (features). **Prerequisites** 1. Build the catboost evaluation library Before evaluating catboost models, the `libcatboostmodel.<so|dylib>` library must be made available. See [CatBoost documentation](https://catboost.ai/docs/concepts/c-plus-plus-api_dynamic-c-pluplus-wrapper.html) how to compile it. Next, specify the path to `libcatboostmodel.<so|dylib>` in the clickhouse configuration: ``` <clickhouse> ... <catboost_lib_path>/path/to/libcatboostmodel.so</catboost_lib_path> ... </clickhouse> ``` For security and isolation reasons, the model evaluation does not run in the server process but in the clickhouse-library-bridge process. At the first execution of `catboostEvaluate()`, the server starts the library bridge process if it is not running already. Both processes communicate using a HTTP interface. By default, port `9012` is used. A different port can be specified as follows - this is useful if port `9012` is already assigned to a different service. ``` <library_bridge> <port>9019</port> </library_bridge> ``` 1. Train a catboost model using libcatboost See [Training and applying models](https://catboost.ai/docs/features/training.html#training) for how to train catboost models from a training data set. **Syntax** ``` catboostEvaluate(path_to_model, feature_1[, feature_2, ..., feature_n]) ``` **Arguments** - `path_to_model` β€” Path to catboost model. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `feature` β€” One or more model features/arguments. [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) **Returned value** Returns the model evaluation result. [`Float64`](https://clickhouse.com/docs/sql-reference/data-types/float) **Examples** **catboostEvaluate** Query ``` SELECT catboostEvaluate('/root/occupy.bin', Temperature, Humidity, Light, CO2, HumidityRatio) AS prediction FROM occupancy LIMIT 1 ``` Response ``` 4.695691092573497 ``` ## colorOKLABToSRGB[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#colorOKLABToSRGB "Direct link to colorOKLABToSRGB") Introduced in: v26.2.0 Converts a color from the OKLab perceptual color space to the sRGB color space. The input color is specified in the OKLab color space. If the input values are outside the typical OKLab ranges, the result is implementation-defined. OKLab uses three components: - L: perceptual lightness (typically in the range \[0..1\]) - a: green-red opponent axis - b: blue-yellow opponent axis The a and b components are theoretically unbounded, but in practice are between -0.4 and 0.4. OKLab is designed to be perceptually uniform while remaining inexpensive to compute. The conversion is intended to be the inverse of colorSRGBToOKLAB and consists of the following stages: 1. Conversion from OKLab to linear sRGB. 2. Conversion from linear sRGB to gamma-encoded sRGB. The optional gamma argument specifies the exponent used when converting from linear sRGB to gamma-encoded RGB values. If not specified, a default gamma value is used for consistency with colorSRGBToOKLAB. For more information about the OKLab color space and its relationship to sRGB, see <https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/color_value/oklab> . **Syntax** ``` colorOKLABToSRGB(tuple [, gamma]) ``` **Arguments** - `tuple` β€” A tuple of three numeric values `L`, `a`, `b`, where `L` is in the range `[0...1]`. [`Tuple(Float64, Float64, Float64)`](https://clickhouse.com/docs/sql-reference/data-types/tuple) - `gamma` β€” Optional. The exponent that is used to transform linear sRGB back to sRGB by applying `(x ^ (1 / gamma)) * 255` for each channel `x`. Defaults to `2.2`. [`Float64`](https://clickhouse.com/docs/sql-reference/data-types/float) **Returned value** Returns a tuple (R, G, B) representing sRGB color values. [`Tuple(Float64, Float64, Float64)`](https://clickhouse.com/docs/sql-reference/data-types/tuple) **Examples** **Convert OKLAB to sRGB (Float)** Query ``` SELECT colorOKLABToSRGB((0.4466, 0.0991, 0.44)) AS rgb; ``` Response ``` β”Œβ”€rgb──────────────────────┐ β”‚ (198.07056923258935,0,0) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Convert OKLAB to sRGB (UInt8)** Query ``` WITH colorOKLABToSRGB((0.7, 0.1, 0.54)) AS t SELECT tuple(toUInt8(t.1), toUInt8(t.2), toUInt8(t.3)) AS RGB; ``` Response ``` β”Œβ”€RGB──────────┐ β”‚ (255,0,0) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## colorOKLCHToSRGB[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#colorOKLCHToSRGB "Direct link to colorOKLCHToSRGB") Introduced in: v25.7.0 Converts a colour from the **OKLCH** perceptual colour space to the familiar **sRGB** colour space. If `L` is outside the range `[0...1]`, `C` is negative, or `H` is outside the range `[0...360]`, the result is implementation-defined. Note **OKLCH** is a cylindrical version of the OKLab colour space. It's three coordinates are `L` (the lightness in the range `[0...1]`), `C` (chroma `>= 0`) and `H` (hue in degrees from `[0...360]`). OKLab/OKLCH is designed to be perceptually uniform while remaining cheap to compute. The conversion is the inverse of [`colorSRGBToOKLCH`](https://clickhouse.com/docs/sql-reference/functions/other-functions#colorSRGBToOKLCH): 1. OKLCH to OKLab. 2. OKLab to Linear sRGB 3. Linear sRGB to sRGB The second argument gamma is used at the last stage. For references of colors in OKLCH space, and how they correspond to sRGB colors please see <https://oklch.com/>. **Syntax** ``` colorOKLCHToSRGB(tuple [, gamma]) ``` **Arguments** - `tuple` β€” A tuple of three numeric values `L`, `C`, `H`, where `L` is in the range `[0...1]`, `C >= 0` and `H` is in the range `[0...360]`. [`Tuple(Float64, Float64, Float64)`](https://clickhouse.com/docs/sql-reference/data-types/tuple) - `gamma` β€” Optional. The exponent that is used to transform linear sRGB back to sRGB by applying `(x ^ (1 / gamma)) * 255` for each channel `x`. Defaults to `2.2`. [`Float64`](https://clickhouse.com/docs/sql-reference/data-types/float) **Returned value** Returns a tuple (R, G, B) representing sRGB color values. [`Tuple(Float64, Float64, Float64)`](https://clickhouse.com/docs/sql-reference/data-types/tuple) **Examples** **Convert OKLCH to sRGB** ``` SELECT colorOKLCHToSRGB((0.6, 0.12, 40)) AS rgb; ``` ``` β”Œβ”€rgb───────────────────────────────────────────────────────┐ β”‚ (186.02058688365264,100.68677189684993,71.67819977081575) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Convert OKLCH to sRGB (UInt8)** ``` WITH colorOKLCHToSRGB((0.6, 0.12, 40)) AS t SELECT tuple(toUInt8(t.1), toUInt8(t.2), toUInt8(t.3)) AS RGB; ``` ``` β”Œβ”€RGB──────────┐ β”‚ (186,100,71) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## colorSRGBToOKLAB[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#colorSRGBToOKLAB "Direct link to colorSRGBToOKLAB") Introduced in: v26.2.0 Converts a colour encoded in the **sRGB** colour space to the perceptually uniform **OKLAB** colour space. If any input channel is outside `[0...255]` or the gamma value is non-positive, the behaviour is implementation-defined. Note **OKLAB** is a perceptually uniform color space. Its three coordinates are `L` (the lightness in the range `[0...1]`), `a (Green-Red axis)` and `b (Blue-Yellow axis)`. OKLab is designed to be perceptually uniform while remaining cheap to compute. The conversion consists of two stages: 1. sRGB to Linear sRGB 2. Linear sRGB to OKLab **Syntax** ``` colorSRGBToOKLAB(tuple[, gamma]) ``` **Arguments** - `tuple` β€” Tuple of three values R, G, B in the range `[0...255]`. [`Tuple(UInt8, UInt8, UInt8)`](https://clickhouse.com/docs/sql-reference/data-types/tuple) - `gamma` β€” Optional. Exponent that is used to linearize sRGB by applying `(x / 255)^gamma` to each channel `x`. Defaults to `2.2`. [`Float64`](https://clickhouse.com/docs/sql-reference/data-types/float) **Returned value** Returns a tuple (L, a, b) representing the OKLAB color space values. [`Tuple(Float64, Float64, Float64)`](https://clickhouse.com/docs/sql-reference/data-types/tuple) **Examples** **Convert sRGB to OKLAB** ``` SELECT colorSRGBToOKLAB((128, 64, 32), 2.2) AS lab; ``` ``` β”Œβ”€lab──────────────────────────────────────────────────────────┐ β”‚ (0.4436238384931984,0.07266246769242975,0.07500108778529994) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## colorSRGBToOKLCH[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#colorSRGBToOKLCH "Direct link to colorSRGBToOKLCH") Introduced in: v25.7.0 Converts a colour encoded in the **sRGB** colour space to the perceptually uniform **OKLCH** colour space. If any input channel is outside `[0...255]` or the gamma value is non-positive, the behaviour is implementation-defined. Note **OKLCH** is a cylindrical version of the OKLab colour space. It's three coordinates are `L` (the lightness in the range `[0...1]`), `C` (chroma `>= 0`) and `H` (the hue in degrees from `[0...360]`). OKLab/OKLCH is designed to be perceptually uniform while remaining cheap to compute. The conversion consists of three stages: 1. sRGB to Linear sRGB 2. Linear sRGB to OKLab 3. OKLab to OKLCH. For references of colors in the OKLCH space, and how they correspond to sRGB colors, please see <https://OKLCH.com/>. **Syntax** ``` colorSRGBToOKLCH(tuple[, gamma]) ``` **Arguments** - `tuple` β€” Tuple of three values R, G, B in the range `[0...255]`. [`Tuple(UInt8, UInt8, UInt8)`](https://clickhouse.com/docs/sql-reference/data-types/tuple) - `gamma` β€” Optional. Exponent that is used to linearize sRGB by applying `(x / 255)^gamma` to each channel `x`. Defaults to `2.2`. [`Float64`](https://clickhouse.com/docs/sql-reference/data-types/float) **Returned value** Returns a tuple (L, C, H) representing the OKLCH color space values. [`Tuple(Float64, Float64, Float64)`](https://clickhouse.com/docs/sql-reference/data-types/tuple) **Examples** **Convert sRGB to OKLCH** ``` SELECT colorSRGBToOKLCH((128, 64, 32), 2.2) AS lch; ``` ``` β”Œβ”€lch───────────────────────────────────────────────────────┐ β”‚ (0.4436238384931984,0.1044269954567863,45.90734548193018) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## connectionId[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#connectionId "Direct link to connectionId") Introduced in: v21.3.0 Returns the connection ID of the client that submitted the current query. This function is most useful in debugging scenarios. It was created for compatibility with MySQL's `CONNECTION_ID` function. It is not typically used in production queries. **Syntax** ``` connectionId() ``` **Arguments** - None. **Returned value** Returns the connection ID of the current client. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT connectionId(); ``` ``` β”Œβ”€connectionId()─┐ β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## countDigits[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#countDigits "Direct link to countDigits") Introduced in: v20.8.0 Returns the number of decimal digits needed to represent a value. Note This function takes into account the scales of decimal values i.e., it calculates the result over the underlying integer type which is `(value * scale)`. For example: - `countDigits(42) = 2` - `countDigits(42.000) = 5` - `countDigits(0.04200) = 4` Tip You can check decimal overflow for `Decimal64` with `countDigits(x) > 18`, although it is slower than [`isDecimalOverflow`](https://clickhouse.com/docs/sql-reference/functions/other-functions#isDecimalOverflow). **Syntax** ``` countDigits(x) ``` **Arguments** - `x` β€” An integer or decimal value. [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) **Returned value** Returns the number of digits needed to represent `x`. [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT countDigits(toDecimal32(1, 9)), countDigits(toDecimal32(-1, 9)), countDigits(toDecimal64(1, 18)), countDigits(toDecimal64(-1, 18)), countDigits(toDecimal128(1, 38)), countDigits(toDecimal128(-1, 38)); ``` ``` β”Œβ”€countDigits(toDecimal32(1, 9))─┬─countDigits(toDecimal32(-1, 9))─┬─countDigits(toDecimal64(1, 18))─┬─countDigits(toDecimal64(-1, 18))─┬─countDigits(toDecimal128(1, 38))─┬─countDigits(toDecimal128(-1, 38))─┐ β”‚ 10 β”‚ 10 β”‚ 19 β”‚ 19 β”‚ 39 β”‚ 39 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## currentDatabase[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#currentDatabase "Direct link to currentDatabase") Introduced in: v1.1.0 Returns the name of the current database. Useful in table engine parameters of `CREATE TABLE` queries where you need to specify the database. Also see the [`SET` statement](https://clickhouse.com/docs/sql-reference/statements/use). **Syntax** ``` currentDatabase() ``` **Aliases**: `current_database`, `SCHEMA`, `DATABASE` **Arguments** - None. **Returned value** Returns the current database name. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT currentDatabase() ``` ``` β”Œβ”€currentDatabase()─┐ β”‚ default β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **SQL standard syntax without parentheses** ``` SELECT CURRENT_DATABASE ``` ``` β”Œβ”€CURRENT_DATABASE─┐ β”‚ default β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## currentProfiles[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#currentProfiles "Direct link to currentProfiles") Introduced in: v21.9.0 Returns an array of the setting profiles for the current user. **Syntax** ``` currentProfiles() ``` **Arguments** - None. **Returned value** Returns an array of setting profiles for the current user. [`Array(String)`](https://clickhouse.com/docs/sql-reference/data-types/array) **Examples** **Usage example** ``` SELECT currentProfiles(); ``` ``` β”Œβ”€currentProfiles()─────────────────────────────┐ β”‚ ['default', 'readonly_user', 'web_analytics'] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## currentQueryID[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#currentQueryID "Direct link to currentQueryID") Introduced in: v25.2.0 Returns current Query id. **Syntax** ``` currentQueryID() ``` **Aliases**: `current_query_id` **Arguments** - None. **Returned value** **Examples** **Example** ``` SELECT currentQueryID(); ``` ``` β”Œβ”€currentQueryID()─────────────────────┐ β”‚ 1280d0e8-1a08-4524-be6e-77975bb68e7d β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## currentRoles[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#currentRoles "Direct link to currentRoles") Introduced in: v21.9.0 Returns an array of the roles which are assigned to the current user. **Syntax** ``` currentRoles() ``` **Arguments** - None. **Returned value** Returns an array of the roles which are assigned to the current user. [`Array(String)`](https://clickhouse.com/docs/sql-reference/data-types/array) **Examples** **Usage example** ``` SELECT currentRoles(); ``` ``` β”Œβ”€currentRoles()─────────────────────────────────┐ β”‚ ['sql-console-role:jane.smith@clickhouse.com'] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## currentSchemas[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#currentSchemas "Direct link to currentSchemas") Introduced in: v23.7.0 Same as function [`currentDatabase`](https://clickhouse.com/docs/sql-reference/functions/other-functions#currentDatabase) but - accepts a boolean argument which is ignored - returns the database name as an array with a single value. Function `currentSchemas` only exists for compatibility with PostgreSQL. Please use `currentDatabase` instead. Also see the [`SET` statement](https://clickhouse.com/docs/sql-reference/statements/use). **Syntax** ``` currentSchemas(bool) ``` **Aliases**: `current_schemas` **Arguments** - `bool` β€” A boolean value, which is ignored. [`Bool`](https://clickhouse.com/docs/sql-reference/data-types/boolean) **Returned value** Returns a single-element array with the name of the current database. [`Array(String)`](https://clickhouse.com/docs/sql-reference/data-types/array) **Examples** **Usage example** ``` SELECT currentSchemas(true) ``` ``` β”Œβ”€currentSchemas(true)─┐ β”‚ ['default'] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## currentUser[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#currentUser "Direct link to currentUser") Introduced in: v20.1.0 Returns the name of the current user. In case of a distributed query, the name of the user who initiated the query is returned. **Syntax** ``` currentUser() ``` **Aliases**: `current_user`, `user` **Arguments** - None. **Returned value** Returns the name of the current user, otherwise the login of the user who initiated the query. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT currentUser() ``` ``` β”Œβ”€currentUser()─┐ β”‚ default β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **SQL standard syntax without parentheses** ``` SELECT CURRENT_USER ``` ``` β”Œβ”€CURRENT_USER─┐ β”‚ default β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## defaultProfiles[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#defaultProfiles "Direct link to defaultProfiles") Introduced in: v21.9.0 Returns an array of default setting profile names for the current user. **Syntax** ``` defaultProfiles() ``` **Arguments** - None. **Returned value** Returns an array of default setting profile names for the current user. [`Array(String)`](https://clickhouse.com/docs/sql-reference/data-types/array) **Examples** **Usage example** ``` SELECT defaultProfiles(); ``` ``` β”Œβ”€defaultProfiles()─┐ β”‚ ['default'] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## defaultRoles[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#defaultRoles "Direct link to defaultRoles") Introduced in: v21.9.0 Returns an array of default roles for the current user. **Syntax** ``` defaultRoles() ``` **Arguments** - None. **Returned value** Returns an array of default roles for the current user. [`Array(String)`](https://clickhouse.com/docs/sql-reference/data-types/array) **Examples** **Usage example** ``` SELECT defaultRoles(); ``` ``` β”Œβ”€defaultRoles()─────────────────────────────────┐ β”‚ ['sql-console-role:jane.smith@clickhouse.com'] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## defaultValueOfArgumentType[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#defaultValueOfArgumentType "Direct link to defaultValueOfArgumentType") Introduced in: v1.1.0 Returns the default value for a given data type. Does not include default values for custom columns set by the user. **Syntax** ``` defaultValueOfArgumentType(expression) ``` **Arguments** - `expression` β€” Arbitrary type of value or an expression that results in a value of an arbitrary type. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns `0` for numbers, an empty string for strings or `NULL` for Nullable types. [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`NULL`](https://clickhouse.com/docs/sql-reference/syntax#null) **Examples** **Usage example** ``` SELECT defaultValueOfArgumentType(CAST(1 AS Int8)); ``` ``` β”Œβ”€defaultValueOfArgumentType(CAST(1, 'Int8'))─┐ β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Nullable example** ``` SELECT defaultValueOfArgumentType(CAST(1 AS Nullable(Int8))); ``` ``` β”Œβ”€defaultValueOfArgumentType(CAST(1, 'Nullable(Int8)'))─┐ β”‚ ᴺᡁᴸᴸ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## defaultValueOfTypeName[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#defaultValueOfTypeName "Direct link to defaultValueOfTypeName") Introduced in: v1.1.0 Returns the default value for the given type name. **Syntax** ``` defaultValueOfTypeName(type) ``` **Arguments** - `type` β€” A string representing a type name. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the default value for the given type name: `0` for numbers, an empty string for strings, or `NULL` for Nullable [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`NULL`](https://clickhouse.com/docs/sql-reference/syntax#null) **Examples** **Usage example** ``` SELECT defaultValueOfTypeName('Int8'); ``` ``` β”Œβ”€defaultValueOfTypeName('Int8')─┐ β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Nullable example** ``` SELECT defaultValueOfTypeName('Nullable(Int8)'); ``` ``` β”Œβ”€defaultValueOfTypeName('Nullable(Int8)')─┐ β”‚ ᴺᡁᴸᴸ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## displayName[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#displayName "Direct link to displayName") Introduced in: v22.11.0 Returns the value of `display_name` from [config](https://clickhouse.com/docs/operations/configuration-files) or the server's Fully Qualified Domain Name (FQDN) if not set. **Syntax** ``` displayName() ``` **Arguments** - None. **Returned value** Returns the value of `display_name` from config or server FQDN if not set. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT displayName(); ``` ``` β”Œβ”€displayName()─┐ β”‚ production β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## dumpColumnStructure[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#dumpColumnStructure "Direct link to dumpColumnStructure") Introduced in: v1.1.0 Outputs a detailed description of the internal structure of a column and its data type. **Syntax** ``` dumpColumnStructure(x) ``` **Arguments** - `x` β€” Value for which to get the description of. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns a description of the column structure used for representing the value. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT dumpColumnStructure(CAST('2018-01-01 01:02:03', 'DateTime')); ``` ``` β”Œβ”€dumpColumnStructure(CAST('2018-01-01 01:02:03', 'DateTime'))─┐ β”‚ DateTime, Const(size = 1, UInt32(size = 1)) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## enabledProfiles[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#enabledProfiles "Direct link to enabledProfiles") Introduced in: v21.9.0 Returns an array of setting profile names which are enabled for the current user. **Syntax** ``` enabledProfiles() ``` **Arguments** - None. **Returned value** Returns an array of setting profile names which are enabled for the current user. [`Array(String)`](https://clickhouse.com/docs/sql-reference/data-types/array) **Examples** **Usage example** ``` SELECT enabledProfiles(); ``` ``` β”Œβ”€enabledProfiles()─────────────────────────────────────────────────┐ β”‚ ['default', 'readonly_user', 'web_analytics', 'batch_processing'] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## enabledRoles[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#enabledRoles "Direct link to enabledRoles") Introduced in: v21.9.0 Returns an array of the roles which are enabled for the current user. **Syntax** ``` enabledRoles() ``` **Arguments** - None. **Returned value** Returns an array of role names which are enabled for the current user. [`Array(String)`](https://clickhouse.com/docs/sql-reference/data-types/array) **Examples** **Usage example** ``` SELECT enabledRoles(); ``` ``` β”Œβ”€enabledRoles()─────────────────────────────────────────────────┐ β”‚ ['general_data', 'sql-console-role:jane.smith@clickhouse.com'] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## errorCodeToName[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#errorCodeToName "Direct link to errorCodeToName") Introduced in: v20.12.0 Returns the textual name of a numeric ClickHouse error code. The mapping from numeric error codes to error names is available [here](https://github.com/ClickHouse/ClickHouse/blob/master/src/Common/ErrorCodes.cpp). **Syntax** ``` errorCodeToName(error_code) ``` **Arguments** - `error_code` β€” ClickHouse error code. [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) or [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) **Returned value** Returns the textual name of `error_code`. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT errorCodeToName(252); ``` ``` β”Œβ”€errorCodeToName(252)─┐ β”‚ TOO_MANY_PARTS β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## file[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#file "Direct link to file") Introduced in: v21.3.0 Reads a file as a string and loads the data into the specified column. The file content is not interpreted. Also see the [`file`](https://clickhouse.com/docs/sql-reference/table-functions/file) table function. **Syntax** ``` file(path[, default]) ``` **Arguments** - `path` β€” The path of the file relative to the `user_files_path`. Supports wildcards `*`, `**`, `?`, `{abc,def}` and `{N..M}` where `N`, `M` are numbers and `'abc', 'def'` are strings. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `default` β€” The value returned if the file does not exist or cannot be accessed. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`NULL`](https://clickhouse.com/docs/sql-reference/syntax#null) **Returned value** Returns the file content as a string. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Insert files into a table** ``` INSERT INTO table SELECT file('a.txt'), file('b.txt'); ``` ## filesystemAvailable[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#filesystemAvailable "Direct link to filesystemAvailable") Introduced in: v20.1.0 Returns the amount of free space in the filesystem hosting the database persistence. The returned value is always smaller than the total free space ([`filesystemUnreserved`](https://clickhouse.com/docs/sql-reference/functions/other-functions#filesystemUnreserved)) because some space is reserved for the operating system. **Syntax** ``` filesystemAvailable([disk_name]) ``` **Arguments** - `disk_name` β€” Optional. The disk name to find the amount of free space for. If omitted, uses the default disk. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`FixedString`](https://clickhouse.com/docs/sql-reference/data-types/fixedstring) **Returned value** Returns the amount of remaining space available in bytes. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT formatReadableSize(filesystemAvailable()) AS "Available space"; ``` ``` β”Œβ”€Available space─┐ β”‚ 30.75 GiB β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## filesystemCapacity[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#filesystemCapacity "Direct link to filesystemCapacity") Introduced in: v20.1.0 Returns the capacity of the filesystem in bytes. Needs the [path](https://clickhouse.com/docs/operations/server-configuration-parameters/settings#path) to the data directory to be configured. **Syntax** ``` filesystemCapacity([disk_name]) ``` **Arguments** - `disk_name` β€” Optional. The disk name to get the capacity for. If omitted, uses the default disk. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`FixedString`](https://clickhouse.com/docs/sql-reference/data-types/fixedstring) **Returned value** Returns the capacity of the filesystem in bytes. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT formatReadableSize(filesystemCapacity()) AS "Capacity"; ``` ``` β”Œβ”€Capacity──┐ β”‚ 39.32 GiB β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## filesystemUnreserved[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#filesystemUnreserved "Direct link to filesystemUnreserved") Introduced in: v22.12.0 Returns the total amount of free space on the filesystem hosting the database persistence (previously `filesystemFree`). See also [`filesystemAvailable`](https://clickhouse.com/docs/sql-reference/functions/other-functions#filesystemAvailable). **Syntax** ``` filesystemUnreserved([disk_name]) ``` **Arguments** - `disk_name` β€” Optional. The disk name for which to find the total amount of free space. If omitted, uses the default disk. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`FixedString`](https://clickhouse.com/docs/sql-reference/data-types/fixedstring) **Returned value** Returns the amount of free space in bytes. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT formatReadableSize(filesystemUnreserved()) AS "Free space"; ``` ``` β”Œβ”€Free space─┐ β”‚ 32.39 GiB β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## finalizeAggregation[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#finalizeAggregation "Direct link to finalizeAggregation") Introduced in: v1.1.0 Given an aggregation state, this function returns the result of aggregation (or the finalized state when using a [\-State](https://clickhouse.com/docs/sql-reference/aggregate-functions/combinators#-state) combinator). **Syntax** ``` finalizeAggregation(state) ``` **Arguments** - `state` β€” State of aggregation. [`AggregateFunction`](https://clickhouse.com/docs/sql-reference/data-types/aggregatefunction) **Returned value** Returns the finalized result of aggregation. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **Usage example** ``` SELECT finalizeAggregation(arrayReduce('maxState', [1, 2, 3])); ``` ``` β”Œβ”€finalizeAggregation(arrayReduce('maxState', [1, 2, 3]))─┐ β”‚ 3 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Combined with initializeAggregation** ``` WITH initializeAggregation('sumState', number) AS one_row_sum_state SELECT number, finalizeAggregation(one_row_sum_state) AS one_row_sum, runningAccumulate(one_row_sum_state) AS cumulative_sum FROM numbers(5); ``` ``` β”Œβ”€number─┬─one_row_sum─┬─cumulative_sum─┐ β”‚ 0 β”‚ 0 β”‚ 0 β”‚ β”‚ 1 β”‚ 1 β”‚ 1 β”‚ β”‚ 2 β”‚ 2 β”‚ 3 β”‚ β”‚ 3 β”‚ 3 β”‚ 6 β”‚ β”‚ 4 β”‚ 4 β”‚ 10 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## flipCoordinates[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#flipCoordinates "Direct link to flipCoordinates") Introduced in: v25.10.0 Flips the x and y coordinates of geometric objects. This operation swaps latitude and longitude, which is useful for converting between different coordinate systems or correcting coordinate order. For a Point, it swaps the x and y coordinates. For complex geometries (LineString, Polygon, MultiPolygon, Ring, MultiLineString), it recursively applies the transformation to each coordinate pair. The function supports both individual geometry types (Point, Ring, Polygon, MultiPolygon, LineString, MultiLineString) and the Geometry variant type. **Syntax** ``` flipCoordinates(geometry) ``` **Arguments** - `geometry` β€” The geometry to transform. Supported types: Point (Tuple(Float64, Float64)), Ring (Array(Point)), Polygon (Array(Ring)), MultiPolygon (Array(Polygon)), LineString (Array(Point)), MultiLineString (Array(LineString)), or Geometry (a variant containing any of these types). **Returned value** The geometry with flipped coordinates. The return type matches the input type. [`Point`](https://clickhouse.com/docs/sql-reference/data-types/geo#point) or [`Ring`](https://clickhouse.com/docs/sql-reference/data-types/geo#ring) or [`Polygon`](https://clickhouse.com/docs/sql-reference/data-types/geo#polygon) or [`MultiPolygon`](https://clickhouse.com/docs/sql-reference/data-types/geo#multipolygon) or [`LineString`](https://clickhouse.com/docs/sql-reference/data-types/geo#linestring) or [`MultiLineString`](https://clickhouse.com/docs/sql-reference/data-types/geo#multilinestring) or [`Geometry`](https://clickhouse.com/docs/sql-reference/data-types/geo) **Examples** **basic\_point** ``` SELECT flipCoordinates((1.0, 2.0)); ``` ``` (2.0, 1.0) ``` **ring** ``` SELECT flipCoordinates([(1.0, 2.0), (3.0, 4.0)]); ``` ``` [(2.0, 1.0), (4.0, 3.0)] ``` **polygon** ``` SELECT flipCoordinates([[(1.0, 2.0), (3.0, 4.0)], [(5.0, 6.0), (7.0, 8.0)]]); ``` ``` [[(2.0, 1.0), (4.0, 3.0)], [(6.0, 5.0), (8.0, 7.0)]] ``` **geometry\_wkt** ``` SELECT flipCoordinates(readWkt('POINT(10 20)')); ``` ``` (20, 10) ``` **geometry\_polygon\_wkt** ``` SELECT flipCoordinates(readWkt('POLYGON((0 0, 5 0, 5 5, 0 5, 0 0))')); ``` ``` [[(0, 0), (0, 5), (5, 5), (5, 0), (0, 0)]] ``` ## formatQuery[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatQuery "Direct link to formatQuery") Introduced in: v23.10.0 Returns a formatted, possibly multi-line, version of the given SQL query. Throws in case of a parsing error. \[example:multiline\] **Syntax** ``` formatQuery(query) ``` **Arguments** - `query` β€” The SQL query to be formatted. [String](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** The formatted query [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **multiline** ``` SELECT formatQuery('select a, b FRom tab WHERE a > 3 and b < 3'); ``` ``` SELECT a, b FROM tab WHERE (a > 3) AND (b < 3) ``` ## formatQueryOrNull[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatQueryOrNull "Direct link to formatQueryOrNull") Introduced in: v23.11.0 Returns a formatted, possibly multi-line, version of the given SQL query. Returns NULL in case of a parsing error. \[example:multiline\] **Syntax** ``` formatQueryOrNull(query) ``` **Arguments** - `query` β€” The SQL query to be formatted. [String](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** The formatted query [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **multiline** ``` SELECT formatQuery('select a, b FRom tab WHERE a > 3 and b < 3'); ``` ``` SELECT a, b FROM tab WHERE (a > 3) AND (b < 3) ``` ## formatQuerySingleLine[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatQuerySingleLine "Direct link to formatQuerySingleLine") Introduced in: v23.10.0 Like formatQuery() but the returned formatted string contains no line breaks. Throws in case of a parsing error. \[example:multiline\] **Syntax** ``` formatQuerySingleLine(query) ``` **Arguments** - `query` β€” The SQL query to be formatted. [String](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** The formatted query [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **multiline** ``` SELECT formatQuerySingleLine('select a, b FRom tab WHERE a > 3 and b < 3'); ``` ``` SELECT a, b FROM tab WHERE (a > 3) AND (b < 3) ``` ## formatQuerySingleLineOrNull[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatQuerySingleLineOrNull "Direct link to formatQuerySingleLineOrNull") Introduced in: v23.11.0 Like formatQuery() but the returned formatted string contains no line breaks. Returns NULL in case of a parsing error. \[example:multiline\] **Syntax** ``` formatQuerySingleLineOrNull(query) ``` **Arguments** - `query` β€” The SQL query to be formatted. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** The formatted query [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **multiline** ``` SELECT formatQuerySingleLine('select a, b FRom tab WHERE a > 3 and b < 3'); ``` ``` SELECT a, b FROM tab WHERE (a > 3) AND (b < 3) ``` ## formatReadableDecimalSize[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatReadableDecimalSize "Direct link to formatReadableDecimalSize") Introduced in: v22.11.0 Given a size (number of bytes), this function returns a readable, rounded size with suffix (KB, MB, etc.) as a string. The opposite operations of this function are [`parseReadableSize`](https://clickhouse.com/docs/sql-reference/functions/other-functions#parseReadableSize). **Syntax** ``` formatReadableDecimalSize(x) ``` **Arguments** - `x` β€” Size in bytes. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Returned value** Returns a readable, rounded size with suffix as a string. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Format file sizes** ``` SELECT arrayJoin([1, 1024, 1024*1024, 192851925]) AS filesize_bytes, formatReadableDecimalSize(filesize_bytes) AS filesize ``` ``` β”Œβ”€filesize_bytes─┬─filesize───┐ β”‚ 1 β”‚ 1.00 B β”‚ β”‚ 1024 β”‚ 1.02 KB β”‚ β”‚ 1048576 β”‚ 1.05 MB β”‚ β”‚ 192851925 β”‚ 192.85 MB β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## formatReadableQuantity[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatReadableQuantity "Direct link to formatReadableQuantity") Introduced in: v20.10.0 Given a number, this function returns a rounded number with suffix (thousand, million, billion, etc.) as a string. This function accepts any numeric type as input, but internally it casts them to `Float64`. Results might be suboptimal with large values. **Syntax** ``` formatReadableQuantity(x) ``` **Arguments** - `x` β€” A number to format. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Returned value** Returns a rounded number with suffix as a string. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Format numbers with suffixes** ``` SELECT arrayJoin([1024, 1234 * 1000, (4567 * 1000) * 1000, 98765432101234]) AS number, formatReadableQuantity(number) AS number_for_humans ``` ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€number─┬─number_for_humans─┐ β”‚ 1024 β”‚ 1.02 thousand β”‚ β”‚ 1234000 β”‚ 1.23 million β”‚ β”‚ 4567000000 β”‚ 4.57 billion β”‚ β”‚ 98765432101234 β”‚ 98.77 trillion β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## formatReadableSize[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatReadableSize "Direct link to formatReadableSize") Introduced in: v1.1.0 Given a size (number of bytes), this function returns a readable, rounded size with suffix (KiB, MiB, etc.) as string. The opposite operations of this function are [`parseReadableSize`](https://clickhouse.com/docs/sql-reference/functions/other-functions#parseReadableSize), [`parseReadableSizeOrZero`](https://clickhouse.com/docs/sql-reference/functions/other-functions#parseReadableSizeOrZero), and [`parseReadableSizeOrNull`](https://clickhouse.com/docs/sql-reference/functions/other-functions#parseReadableSizeOrNull). This function accepts any numeric type as input, but internally it casts them to `Float64`. Results might be suboptimal with large values. **Syntax** ``` formatReadableSize(x) ``` **Aliases**: `FORMAT_BYTES` **Arguments** - `x` β€” Size in bytes. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Returned value** Returns a readable, rounded size with suffix as a string. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Format file sizes** ``` SELECT arrayJoin([1, 1024, 1024*1024, 192851925]) AS filesize_bytes, formatReadableSize(filesize_bytes) AS filesize ``` ``` β”Œβ”€filesize_bytes─┬─filesize───┐ β”‚ 1 β”‚ 1.00 B β”‚ β”‚ 1024 β”‚ 1.00 KiB β”‚ β”‚ 1048576 β”‚ 1.00 MiB β”‚ β”‚ 192851925 β”‚ 183.92 MiB β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## formatReadableTimeDelta[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatReadableTimeDelta "Direct link to formatReadableTimeDelta") Introduced in: v20.12.0 Given a time interval (delta) in seconds, this function returns a time delta with year/month/day/hour/minute/second/millisecond/microsecond/nanosecond as a string. This function accepts any numeric type as input, but internally it casts them to `Float64`. Results might be suboptimal with large values. **Syntax** ``` formatReadableTimeDelta(column[, maximum_unit, minimum_unit]) ``` **Arguments** - `column` β€” A column with a numeric time delta. [`Float64`](https://clickhouse.com/docs/sql-reference/data-types/float) - `maximum_unit` β€” Optional. Maximum unit to show. Acceptable values: `nanoseconds`, `microseconds`, `milliseconds`, `seconds`, `minutes`, `hours`, `days`, `months`, `years`. Default value: `years`. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `minimum_unit` β€” Optional. Minimum unit to show. All smaller units are truncated. Acceptable values: `nanoseconds`, `microseconds`, `milliseconds`, `seconds`, `minutes`, `hours`, `days`, `months`, `years`. If explicitly specified value is bigger than `maximum_unit`, an exception will be thrown. Default value: `seconds` if `maximum_unit` is `seconds` or bigger, `nanoseconds` otherwise. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns a time delta as a string. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT arrayJoin([100, 12345, 432546534]) AS elapsed, formatReadableTimeDelta(elapsed) AS time_delta ``` ``` β”Œβ”€β”€β”€β”€elapsed─┬─time_delta─────────────────────────────────────────────────────┐ β”‚ 100 β”‚ 1 minute and 40 seconds β”‚ β”‚ 12345 β”‚ 3 hours, 25 minutes and 45 seconds β”‚ β”‚ 432546534 β”‚ 13 years, 8 months, 17 days, 7 hours, 48 minutes and 54 secondsβ”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **With maximum unit** ``` SELECT arrayJoin([100, 12345, 432546534]) AS elapsed, formatReadableTimeDelta(elapsed, 'minutes') AS time_delta ``` ``` β”Œβ”€β”€β”€β”€elapsed─┬─time_delta─────────────────────────────────────────────────────┐ β”‚ 100 β”‚ 1 minute and 40 seconds β”‚ β”‚ 12345 β”‚ 205 minutes and 45 seconds β”‚ β”‚ 432546534 β”‚ 7209108 minutes and 54 seconds β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## fuzzQuery[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#fuzzQuery "Direct link to fuzzQuery") Introduced in: v26.2.0 Parses the given query string and applies random AST mutations (fuzzing) to it. Returns the fuzzed query as a string. Non-deterministic: each call may produce a different result. Requires `allow_fuzz_query_functions = 1`. **Syntax** ``` fuzzQuery(query) ``` **Arguments** - `query` β€” The SQL query to be fuzzed. [String](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** The fuzzed query string [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **basic** ``` SET allow_fuzz_query_functions = 1; SELECT fuzzQuery('SELECT 1'); ``` ## generateRandomStructure[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#generateRandomStructure "Direct link to generateRandomStructure") Introduced in: v23.5.0 Generates random table structure in the format `column1_name column1_type, column2_name column2_type, ...`. **Syntax** ``` generateRandomStructure([number_of_columns, seed]) ``` **Arguments** - `number_of_columns` β€” The desired number of columns in the resultant table structure. If set to 0 or `Null`, the number of columns will be random from 1 to 128. Default value: `Null`. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) - `seed` β€” Random seed to produce stable results. If seed is not specified or set to `Null`, it is randomly generated. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Returned value** Randomly generated table structure. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT generateRandomStructure() ``` ``` c1 Decimal32(5), c2 Date, c3 Tuple(LowCardinality(String), Int128, UInt64, UInt16, UInt8, IPv6), c4 Array(UInt128), c5 UInt32, c6 IPv4, c7 Decimal256(64), c8 Decimal128(3), c9 UInt256, c10 UInt64, c11 DateTime ``` **with specified number of columns** ``` SELECT generateRandomStructure(1) ``` ``` c1 Map(UInt256, UInt16) ``` **with specified seed** ``` SELECT generateRandomStructure(NULL, 33) ``` ``` c1 DateTime, c2 Enum8('c2V0' = 0, 'c2V1' = 1, 'c2V2' = 2, 'c2V3' = 3), c3 LowCardinality(Nullable(FixedString(30))), c4 Int16, c5 Enum8('c5V0' = 0, 'c5V1' = 1, 'c5V2' = 2, 'c5V3' = 3), c6 Nullable(UInt8), c7 String, c8 Nested(e1 IPv4, e2 UInt8, e3 UInt16, e4 UInt16, e5 Int32, e6 Map(Date, Decimal256(70))) ``` ## generateSerialID[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#generateSerialID "Direct link to generateSerialID") Introduced in: v25.1.0 Generates and returns sequential numbers starting from the previous counter value. This function takes a string argument - a series identifier, and an optional starting value. The server should be configured with Keeper. The series are stored in Keeper nodes under the path, which can be configured in [`series_keeper_path`](https://clickhouse.com/docs/operations/server-configuration-parameters/settings#series_keeper_path) in the server configuration. **Syntax** ``` generateSerialID(series_identifier[, start_value]) ``` **Arguments** - `series_identifier` β€” Series identifier [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `start_value` β€” Optional. Starting value for the counter. Defaults to 0. Note: this value is only used when creating a new series and is ignored if the series already exists [`UInt*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Returned value** Returns sequential numbers starting from the previous counter value. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **first call** ``` SELECT generateSerialID('id1') ``` ``` β”Œβ”€generateSerialID('id1')──┐ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **second call** ``` SELECT generateSerialID('id1') ``` ``` β”Œβ”€generateSerialID('id1')──┐ β”‚ 2 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **column call** ``` SELECT *, generateSerialID('id1') FROM test_table ``` ``` β”Œβ”€CounterID─┬─UserID─┬─ver─┬─generateSerialID('id1')──┐ β”‚ 1 β”‚ 3 β”‚ 3 β”‚ 3 β”‚ β”‚ 1 β”‚ 1 β”‚ 1 β”‚ 4 β”‚ β”‚ 1 β”‚ 2 β”‚ 2 β”‚ 5 β”‚ β”‚ 1 β”‚ 5 β”‚ 5 β”‚ 6 β”‚ β”‚ 1 β”‚ 4 β”‚ 4 β”‚ 7 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **with start value** ``` SELECT generateSerialID('id2', 100) ``` ``` β”Œβ”€generateSerialID('id2', 100)──┐ β”‚ 100 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **with start value second call** ``` SELECT generateSerialID('id2', 100) ``` ``` β”Œβ”€generateSerialID('id2', 100)──┐ β”‚ 101 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` Introduced in: v24.5.0 Gets the value of an HTTP header. If there is no such header or the current request is not performed via the HTTP interface, the function returns an empty string. Certain HTTP headers (e.g., `Authentication` and `X-ClickHouse-*`) are restricted. Note Setting `allow_get_client_http_header` is required The function requires the setting `allow_get_client_http_header` to be enabled. The setting is not enabled by default for security reasons, because some headers, such as `Cookie`, could contain sensitive info. HTTP headers are case sensitive for this function. If the function is used in the context of a distributed query, it returns non-empty result only on the initiator node. **Syntax** ``` getClientHTTPHeader(name) ``` **Arguments** - `name` β€” The HTTP header name. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the value of the header. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT getClientHTTPHeader('Content-Type'); ``` ``` β”Œβ”€getClientHTTPHeader('Content-Type')─┐ β”‚ application/x-www-form-urlencoded β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## getMacro[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#getMacro "Direct link to getMacro") Introduced in: v20.1.0 Returns the value of a macro from the server configuration file. Macros are defined in the [`<macros>`](https://clickhouse.com/docs/operations/server-configuration-parameters/settings#macros) section of the configuration file and can be used to distinguish servers by convenient names even if they have complicated hostnames. If the function is executed in the context of a distributed table, it generates a normal column with values relevant to each shard. **Syntax** ``` getMacro(name) ``` **Arguments** - `name` β€” The name of the macro to retrieve. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the value of the specified macro. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Basic usage** ``` SELECT getMacro('test'); ``` ``` β”Œβ”€getMacro('test')─┐ β”‚ Value β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## getMaxTableNameLengthForDatabase[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#getMaxTableNameLengthForDatabase "Direct link to getMaxTableNameLengthForDatabase") Introduced in: v25.1.0 Returns the maximum table name length in a specified database. **Syntax** ``` getMaxTableNameLengthForDatabase(database_name) ``` **Arguments** - `database_name` β€” The name of the specified database. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the length of the maximum table name, an Integer **Examples** **typical** ``` SELECT getMaxTableNameLengthForDatabase('default'); ``` ``` β”Œβ”€getMaxTableNameLengthForDatabase('default')─┐ β”‚ 206 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## getMergeTreeSetting[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#getMergeTreeSetting "Direct link to getMergeTreeSetting") Introduced in: v25.6.0 Returns the current value of a MergeTree setting. **Syntax** ``` getMergeTreeSetting(setting_name) ``` **Arguments** - `setting_name` β€” The setting name. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the merge tree setting's current value. **Examples** **Usage example** ``` SELECT getMergeTreeSetting('index_granularity'); ``` ``` β”Œβ”€getMergeTreeSetting('index_granularity')─┐ β”‚ 8192 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## getOSKernelVersion[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#getOSKernelVersion "Direct link to getOSKernelVersion") Introduced in: v21.11.0 Returns a string with the OS kernel version. **Syntax** ``` getOSKernelVersion() ``` **Arguments** - None. **Returned value** Returns the current OS kernel version. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT getOSKernelVersion(); ``` ``` β”Œβ”€getOSKernelVersion()────┐ β”‚ Linux 4.15.0-55-generic β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## getServerPort[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#getServerPort "Direct link to getServerPort") Introduced in: v21.10.0 Returns the server's port number for a given protocol. **Syntax** ``` getServerPort(port_name) ``` **Arguments** - `port_name` β€” The name of the port. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the server port number. [`UInt16`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT getServerPort('tcp_port'); ``` ``` β”Œβ”€getServerPort('tcp_port')─┐ β”‚ 9000 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## getServerSetting[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#getServerSetting "Direct link to getServerSetting") Introduced in: v25.6.0 Returns the currently set value, given a server setting name. **Syntax** ``` getServerSetting(setting_name') ``` **Arguments** - `setting_name` β€” The server setting name. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the server setting's current value. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **Usage example** ``` SELECT getServerSetting('allow_use_jemalloc_memory'); ``` ``` β”Œβ”€getServerSetting('allow_use_jemalloc_memory')─┐ β”‚ true β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## getSetting[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#getSetting "Direct link to getSetting") Introduced in: v20.7.0 Returns the current value of a setting. **Syntax** ``` getSetting(setting_name) ``` **Arguments** - `setting_Name` β€” The setting name. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the setting's current value. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **Usage example** ``` SELECT getSetting('enable_analyzer'); SET enable_analyzer = false; SELECT getSetting('enable_analyzer'); ``` ``` β”Œβ”€getSetting('β‹―_analyzer')─┐ β”‚ true β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€getSetting('β‹―_analyzer')─┐ β”‚ false β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## getSettingOrDefault[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#getSettingOrDefault "Direct link to getSettingOrDefault") Introduced in: v24.10.0 Returns the current value of a setting or returns the default value specified in the second argument if the setting is not set in the current profile. **Syntax** ``` getSettingOrDefault(setting_name, default_value) ``` **Arguments** - `setting_name` β€” The setting name. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `default_value` β€” Value to return if custom\_setting is not set. Value may be of any data type or Null. **Returned value** Returns the current value of the specified setting or `default_value` if the setting is not set. **Examples** **Usage example** ``` SELECT getSettingOrDefault('custom_undef1', 'my_value'); SELECT getSettingOrDefault('custom_undef2', 100); SELECT getSettingOrDefault('custom_undef3', NULL); ``` ``` my_value 100 NULL ``` ## getSizeOfEnumType[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#getSizeOfEnumType "Direct link to getSizeOfEnumType") Introduced in: v1.1.0 Returns the number of fields in the given [`Enum`](https://clickhouse.com/docs/sql-reference/data-types/enum). **Syntax** ``` getSizeOfEnumType(x) ``` **Arguments** - `x` β€” Value of type `Enum`. [`Enum`](https://clickhouse.com/docs/sql-reference/data-types/enum) **Returned value** Returns the number of fields with `Enum` input values. [`UInt8/16`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT getSizeOfEnumType(CAST('a' AS Enum8('a' = 1, 'b' = 2))) AS x; ``` ``` β”Œβ”€x─┐ β”‚ 2 β”‚ β””β”€β”€β”€β”˜ ``` ## getSubcolumn[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#getSubcolumn "Direct link to getSubcolumn") Introduced in: v23.3.0 Receives the expression or identifier and constant string with the name of subcolumn. Returns requested subcolumn extracted from the expression. **Syntax** ``` getSubcolumn(nested_value, subcolumn_name) ``` **Arguments** - None. **Returned value** **Examples** **getSubcolumn** ``` SELECT getSubcolumn(array_col, 'size0'), getSubcolumn(tuple_col, 'elem_name') ``` ## getTypeSerializationStreams[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#getTypeSerializationStreams "Direct link to getTypeSerializationStreams") Introduced in: v22.6.0 Enumerates stream paths of a data type. This function is intended for developmental use. **Syntax** ``` getTypeSerializationStreams(col) ``` **Arguments** - `col` β€” Column or string representation of a data-type from which the data type will be detected. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns an array with all the serialization sub-stream paths. [`Array(String)`](https://clickhouse.com/docs/sql-reference/data-types/array) **Examples** **tuple** ``` SELECT getTypeSerializationStreams(tuple('a', 1, 'b', 2)) ``` ``` ['{TupleElement(1), Regular}','{TupleElement(2), Regular}','{TupleElement(3), Regular}','{TupleElement(4), Regular}'] ``` **map** ``` SELECT getTypeSerializationStreams('Map(String, Int64)') ``` ``` ['{ArraySizes}','{ArrayElements, TupleElement(keys), Regular}','{ArrayElements, TupleElement(values), Regular}'] ``` ## globalVariable[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#globalVariable "Direct link to globalVariable") Introduced in: v20.5.0 Takes a constant string argument and returns the value of the global variable with that name. This function is intended for compatibility with MySQL and not needed or useful for normal operation of ClickHouse. Only few dummy global variables are defined. **Syntax** ``` globalVariable(name) ``` **Arguments** - `name` β€” Global variable name. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the value of variable `name`. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **globalVariable** ``` SELECT globalVariable('max_allowed_packet') ``` ``` 67108864 ``` ## hasColumnInTable[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#hasColumnInTable "Direct link to hasColumnInTable") Introduced in: v1.1.0 Checks if a specific column exists in a database table. For elements in a nested data structure, the function checks for the existence of a column. For the nested data structure itself, the function returns `0`. **Syntax** ``` hasColumnInTable([hostname[, username[, password]],]database, table, column) ``` **Arguments** - `database` β€” Name of the database. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `table` β€” Name of the table. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `column` β€” Name of the column. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `hostname` β€” Optional. Remote server name to perform the check on. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `username` β€” Optional. Username for remote server. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `password` β€” Optional. Password for remote server. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns `1` if the given column exists, `0` otherwise. [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Check an existing column** ``` SELECT hasColumnInTable('system','metrics','metric') ``` ``` 1 ``` **Check a non-existing column** ``` SELECT hasColumnInTable('system','metrics','non-existing_column') ``` ``` 0 ``` ## hasThreadFuzzer[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#hasThreadFuzzer "Direct link to hasThreadFuzzer") Introduced in: v20.6.0 Returns whether the thread fuzzer is enabled. THis function is only useful for testing and debugging. **Syntax** ``` hasThreadFuzzer() ``` **Arguments** - None. **Returned value** Returns whether Thread Fuzzer is effective. [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Check Thread Fuzzer status** ``` SELECT hasThreadFuzzer() ``` ``` β”Œβ”€hasThreadFuzzer()─┐ β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## hostName[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#hostName "Direct link to hostName") Introduced in: v20.5.0 Returns the name of the host on which this function was executed. If the function executes on a remote server (distributed processing), the remote server name is returned. If the function executes in the context of a distributed table, it generates a normal column with values relevant to each shard. Otherwise it produces a constant value. **Syntax** ``` hostName() ``` **Aliases**: `hostname` **Arguments** - None. **Returned value** Returns the host name. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT hostName() ``` ``` β”Œβ”€hostName()─┐ β”‚ clickhouse β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## icebergBucket[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#icebergBucket "Direct link to icebergBucket") Introduced in: v25.5.0 Implements logic for the [iceberg bucket transform](https://iceberg.apache.org/spec/#bucket-transform-details.) **Syntax** ``` icebergBucket(N, value) ``` **Arguments** - `N` β€” The number of buckets, modulo. [`const (U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) - `value` β€” The source value to transform. [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Bool`](https://clickhouse.com/docs/sql-reference/data-types/boolean) or [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) or [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`FixedString`](https://clickhouse.com/docs/sql-reference/data-types/fixedstring) or [`UUID`](https://clickhouse.com/docs/sql-reference/data-types/uuid) or [`Date`](https://clickhouse.com/docs/sql-reference/data-types/date) or [`Time`](https://clickhouse.com/docs/sql-reference/data-types/time) or [`DateTime`](https://clickhouse.com/docs/sql-reference/data-types/datetime) **Returned value** Returns a 32-bit hash of the source value. [`Int32`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Example** ``` SELECT icebergBucket(5, 1.0 :: Float32) ``` ``` 4 ``` ## icebergTruncate[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#icebergTruncate "Direct link to icebergTruncate") Introduced in: v25.3.0 Implements logic of iceberg truncate transform: <https://iceberg.apache.org/spec/#truncate-transform-details>. **Syntax** ``` icebergTruncate(N, value) ``` **Arguments** - `value` β€” The value to transform. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) **Returned value** The same type as the argument **Examples** **Example** ``` SELECT icebergTruncate(3, 'iceberg') ``` ``` ice ``` ## identity[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#identity "Direct link to identity") Introduced in: v1.1.0 This function returns the argument you pass to it, which is useful for debugging and testing. It lets you bypass index usage to see full scan performance instead. The query analyzer ignores anything inside identity functions when looking for indexes to use, and it also disables constant folding. **Syntax** ``` identity(x) ``` **Arguments** - `x` β€” Input value. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns the input value unchanged. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **Usage example** ``` SELECT identity(42) ``` ``` 42 ``` ## ignore[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#ignore "Direct link to ignore") Introduced in: v1.1.0 Accepts arbitrary arguments and unconditionally returns `0`. **Syntax** ``` ignore(x) ``` **Arguments** - `x` β€” An input value which is unused and passed only so as to avoid a syntax error. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Always returns `0`. [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT ignore(0, 'ClickHouse', NULL) ``` ``` β”Œβ”€ignore(0, 'ClickHouse', NULL)─┐ β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## indexHint[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#indexHint "Direct link to indexHint") Introduced in: v1.1.0 This function is intended for debugging and introspection. It ignores its argument and always returns 1. The arguments are not evaluated. During index analysis, the argument of this function is assumed to not be wrapped in `indexHint`. This allows you to select data in index ranges by the corresponding condition but without further filtering by this condition. The index in ClickHouse is sparse and using `indexHint` will yield more data than specifying the same condition directly. Explanation Note: It is not possible to optimize a query with the `indexHint` function. The `indexHint` function does not optimize the query, as it does not provide any additional information for the query analysis. Having an expression inside the `indexHint` function is not anyhow better than without the `indexHint` function. The `indexHint` function can be used only for introspection and debugging purposes and it does not improve performance. If you see the usage of `indexHint` by anyone other than ClickHouse contributors, it is likely a mistake and you should remove it. **Syntax** ``` indexHint(expression) ``` **Arguments** - `expression` β€” Any expression for index range selection. [`Expression`](https://clickhouse.com/docs/sql-reference/data-types/special-data-types/expression) **Returned value** Returns `1` in all cases. [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example with date filtering** ``` SELECT FlightDate AS k, count() FROM ontime WHERE indexHint(k = '2025-09-15') GROUP BY k ORDER BY k ASC; ``` ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€k─┬─count()─┐ β”‚ 2025-09-14 β”‚ 7071 β”‚ β”‚ 2025-09-15 β”‚ 16428 β”‚ β”‚ 2025-09-16 β”‚ 1077 β”‚ β”‚ 2025-09-30 β”‚ 8167 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## initialQueryID[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#initialQueryID "Direct link to initialQueryID") Introduced in: v1.1.0 Returns the ID of the initial current query. Other parameters of a query can be extracted from field `initial_query_id` in [`system.query_log`](https://clickhouse.com/docs/operations/system-tables/query_log). In contrast to [`queryID`](https://clickhouse.com/docs/sql-reference/functions/other-functions#queryID) function, `initialQueryID` returns the same results on different shards. **Syntax** ``` initialQueryID() ``` **Aliases**: `initial_query_id` **Arguments** - None. **Returned value** Returns the ID of the initial current query. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` CREATE TABLE tmp (str String) ENGINE = Log; INSERT INTO tmp (*) VALUES ('a'); SELECT count(DISTINCT t) FROM (SELECT initialQueryID() AS t FROM remote('127.0.0.{1..3}', currentDatabase(), 'tmp') GROUP BY queryID()); ``` ``` β”Œβ”€count(DISTINCT t)─┐ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## initialQueryStartTime[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#initialQueryStartTime "Direct link to initialQueryStartTime") Introduced in: v25.4.0 Returns the start time of the initial current query. `initialQueryStartTime` returns the same results on different shards. **Syntax** ``` initialQueryStartTime() ``` **Aliases**: `initial_query_start_time` **Arguments** - None. **Returned value** Returns the start time of the initial current query. [`DateTime`](https://clickhouse.com/docs/sql-reference/data-types/datetime) **Examples** **Usage example** ``` CREATE TABLE tmp (str String) ENGINE = Log; INSERT INTO tmp (*) VALUES ('a'); SELECT count(DISTINCT t) FROM (SELECT initialQueryStartTime() AS t FROM remote('127.0.0.{1..3}', currentDatabase(), 'tmp') GROUP BY queryID()); ``` ``` β”Œβ”€count(DISTINCT t)─┐ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## initializeAggregation[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#initializeAggregation "Direct link to initializeAggregation") Introduced in: v20.6.0 Calculates the result of an aggregate function based on a single value. This function can be used to initialize aggregate functions with combinator [\-State](https://clickhouse.com/docs/sql-reference/aggregate-functions/combinators#-state). You can create states of aggregate functions and insert them to columns of type [`AggregateFunction`](https://clickhouse.com/docs/sql-reference/data-types/aggregatefunction) or use initialized aggregates as default values. **Syntax** ``` initializeAggregation(aggregate_function, arg1[, arg2, ...]) ``` **Arguments** - `aggregate_function` β€” Name of the aggregation function to initialize. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `arg1[, arg2, ...]` β€” Arguments of the aggregate function. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns the result of aggregation for every row passed to the function. The return type is the same as the return type of the function that `initializeAggregation` takes as a first argument. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **Basic usage with uniqState** ``` SELECT uniqMerge(state) FROM (SELECT initializeAggregation('uniqState', number % 3) AS state FROM numbers(10000)); ``` ``` β”Œβ”€uniqMerge(state)─┐ β”‚ 3 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Usage with sumState and finalizeAggregation** ``` SELECT finalizeAggregation(state), toTypeName(state) FROM (SELECT initializeAggregation('sumState', number % 3) AS state FROM numbers(5)); ``` ``` β”Œβ”€finalizeAggregation(state)─┬─toTypeName(state)─────────────┐ β”‚ 0 β”‚ AggregateFunction(sum, UInt8) β”‚ β”‚ 1 β”‚ AggregateFunction(sum, UInt8) β”‚ β”‚ 2 β”‚ AggregateFunction(sum, UInt8) β”‚ β”‚ 0 β”‚ AggregateFunction(sum, UInt8) β”‚ β”‚ 1 β”‚ AggregateFunction(sum, UInt8) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## isConstant[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#isConstant "Direct link to isConstant") Introduced in: v20.3.0 Returns whether the argument is a constant expression. A constant expression is an expression whose result is known during query analysis, i.e. before execution. For example, expressions over [literals](https://clickhouse.com/docs/sql-reference/syntax#literals) are constant expressions. This function is mostly intended for development, debugging and demonstration. **Syntax** ``` isConstant(x) ``` **Arguments** - `x` β€” An expression to check. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns `1` if `x` is constant, `0` if `x` is non-constant. [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Constant expression** ``` SELECT isConstant(x + 1) FROM (SELECT 43 AS x) ``` ``` β”Œβ”€isConstant(plus(x, 1))─┐ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Constant with function** ``` WITH 3.14 AS pi SELECT isConstant(cos(pi)) ``` ``` β”Œβ”€isConstant(cos(pi))─┐ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Non-constant expression** ``` SELECT isConstant(number) FROM numbers(1) ``` ``` β”Œβ”€isConstant(number)─┐ β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Behavior of the now() function** ``` SELECT isConstant(now()) ``` ``` β”Œβ”€isConstant(now())─┐ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## isDecimalOverflow[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#isDecimalOverflow "Direct link to isDecimalOverflow") Introduced in: v20.8.0 Checks if a decimal number has too many digits to fit properly in a Decimal data type with given precision. **Syntax** ``` isDecimalOverflow(value[, precision]) ``` **Arguments** - `value` β€” Decimal value to check. [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) - `precision` β€” Optional. The precision of the Decimal type. If omitted, the initial precision of the first argument is used. [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Returned value** Returns `1` if the decimal value has more digits than allowed by its precision, `0` if the decimal value satisfies the specified precision. [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT isDecimalOverflow(toDecimal32(1000000000, 0), 9), isDecimalOverflow(toDecimal32(1000000000, 0)), isDecimalOverflow(toDecimal32(-1000000000, 0), 9), isDecimalOverflow(toDecimal32(-1000000000, 0)); ``` ``` β”Œβ”€isDecimalOverflow(toDecimal32(1000000000, 0), 9)─┬─isDecimalOverflow(toDecimal32(1000000000, 0))─┬─isDecimalOverflow(toDecimal32(-1000000000, 0), 9)─┬─isDecimalOverflow(toDecimal32(-1000000000, 0))─┐ β”‚ 1 β”‚ 1 β”‚ 1 β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## joinGet[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#joinGet "Direct link to joinGet") Introduced in: v18.16.0 Allows you to extract data from a table the same way as from a dictionary. Gets data from Join tables using the specified join key. Note Only supports tables created with the `ENGINE = Join(ANY, LEFT, <join_keys>)` [statement](https://clickhouse.com/docs/engines/table-engines/special/join). **Syntax** ``` joinGet(join_storage_table_name, value_column, join_keys) ``` **Arguments** - `join_storage_table_name` β€” An identifier which indicates where to perform the search. The identifier is searched in the default database (see parameter `default_database` in the config file). To override the default database, use the `USE database_name` query or specify the database and the table through a dot, like `database_name.table_name`. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `value_column` β€” The name of the column of the table that contains required data. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `join_keys` β€” A list of join keys. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns list of values corresponded to list of keys. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **Usage example** ``` CREATE TABLE db_test.id_val(`id` UInt32, `val` UInt32) ENGINE = Join(ANY, LEFT, id); INSERT INTO db_test.id_val VALUES (1,11)(2,12)(4,13); SELECT joinGet(db_test.id_val, 'val', toUInt32(1)); ``` ``` β”Œβ”€joinGet(db_test.id_val, 'val', toUInt32(1))─┐ β”‚ 11 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Usage with table from current database** ``` USE db_test; SELECT joinGet(id_val, 'val', toUInt32(2)); ``` ``` β”Œβ”€joinGet(id_val, 'val', toUInt32(2))─┐ β”‚ 12 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Using arrays as join keys** ``` CREATE TABLE some_table (id1 UInt32, id2 UInt32, name String) ENGINE = Join(ANY, LEFT, id1, id2); INSERT INTO some_table VALUES (1, 11, 'a') (2, 12, 'b') (3, 13, 'c'); SELECT joinGet(some_table, 'name', 1, 11); ``` ``` β”Œβ”€joinGet(some_table, 'name', 1, 11)─┐ β”‚ a β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## joinGetOrNull[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#joinGetOrNull "Direct link to joinGetOrNull") Introduced in: v20.4.0 Allows you to extract data from a table the same way as from a dictionary. Gets data from Join tables using the specified join key. Unlike [`joinGet`](https://clickhouse.com/docs/sql-reference/functions/other-functions#joinGet) it returns `NULL` when the key is missing. Note Only supports tables created with the `ENGINE = Join(ANY, LEFT, <join_keys>)` [statement](https://clickhouse.com/docs/engines/table-engines/special/join). **Syntax** ``` joinGetOrNull(join_storage_table_name, value_column, join_keys) ``` **Arguments** - `join_storage_table_name` β€” An identifier which indicates where to perform the search. The identifier is searched in the default database (see parameter default\_database in the config file). To override the default database, use the `USE database_name` query or specify the database and the table through a dot, like `database_name.table_name`. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `value_column` β€” The name of the column of the table that contains required data. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `join_keys` β€” A list of join keys. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns a list of values corresponding to the list of keys, or `NULL` if a key is not found. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **Usage example** ``` CREATE TABLE db_test.id_val(`id` UInt32, `val` UInt32) ENGINE = Join(ANY, LEFT, id); INSERT INTO db_test.id_val VALUES (1,11)(2,12)(4,13); SELECT joinGetOrNull(db_test.id_val, 'val', toUInt32(1)), joinGetOrNull(db_test.id_val, 'val', toUInt32(999)); ``` ``` β”Œβ”€joinGetOrNull(db_test.id_val, 'val', toUInt32(1))─┬─joinGetOrNull(db_test.id_val, 'val', toUInt32(999))─┐ β”‚ 11 β”‚ ᴺᡁᴸᴸ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## lowCardinalityIndices[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#lowCardinalityIndices "Direct link to lowCardinalityIndices") Introduced in: v18.12.0 Returns the position of a value in the dictionary of a [LowCardinality](https://clickhouse.com/docs/sql-reference/data-types/lowcardinality) column. Positions start at 1. Since LowCardinality have per-part dictionaries, this function may return different positions for the same value in different parts. **Syntax** ``` lowCardinalityIndices(col) ``` **Arguments** - `col` β€” A low cardinality column. [`LowCardinality`](https://clickhouse.com/docs/sql-reference/data-types/lowcardinality) **Returned value** The position of the value in the dictionary of the current part. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage examples** ``` DROP TABLE IF EXISTS test; CREATE TABLE test (s LowCardinality(String)) ENGINE = Memory; -- create two parts: INSERT INTO test VALUES ('ab'), ('cd'), ('ab'), ('ab'), ('df'); INSERT INTO test VALUES ('ef'), ('cd'), ('ab'), ('cd'), ('ef'); SELECT s, lowCardinalityIndices(s) FROM test; ``` ``` β”Œβ”€s──┬─lowCardinalityIndices(s)─┐ β”‚ ab β”‚ 1 β”‚ β”‚ cd β”‚ 2 β”‚ β”‚ ab β”‚ 1 β”‚ β”‚ ab β”‚ 1 β”‚ β”‚ df β”‚ 3 β”‚ β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€s──┬─lowCardinalityIndices(s)─┐ β”‚ ef β”‚ 1 β”‚ β”‚ cd β”‚ 2 β”‚ β”‚ ab β”‚ 3 β”‚ β”‚ cd β”‚ 2 β”‚ β”‚ ef β”‚ 1 β”‚ β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## lowCardinalityKeys[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#lowCardinalityKeys "Direct link to lowCardinalityKeys") Introduced in: v18.12.0 Returns the dictionary values of a [LowCardinality](https://clickhouse.com/docs/sql-reference/data-types/lowcardinality) column. If the block is smaller or larger than the dictionary size, the result will be truncated or extended with default values. Since LowCardinality have per-part dictionaries, this function may return different dictionary values in different parts. **Syntax** ``` lowCardinalityKeys(col) ``` **Arguments** - `col` β€” A low cardinality column. [`LowCardinality`](https://clickhouse.com/docs/sql-reference/data-types/lowcardinality) **Returned value** Returns the dictionary keys. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **lowCardinalityKeys** ``` DROP TABLE IF EXISTS test; CREATE TABLE test (s LowCardinality(String)) ENGINE = Memory; -- create two parts: INSERT INTO test VALUES ('ab'), ('cd'), ('ab'), ('ab'), ('df'); INSERT INTO test VALUES ('ef'), ('cd'), ('ab'), ('cd'), ('ef'); SELECT s, lowCardinalityKeys(s) FROM test; ``` ``` β”Œβ”€s──┬─lowCardinalityKeys(s)─┐ β”‚ ef β”‚ β”‚ β”‚ cd β”‚ ef β”‚ β”‚ ab β”‚ cd β”‚ β”‚ cd β”‚ ab β”‚ β”‚ ef β”‚ β”‚ β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€s──┬─lowCardinalityKeys(s)─┐ β”‚ ab β”‚ β”‚ β”‚ cd β”‚ ab β”‚ β”‚ ab β”‚ cd β”‚ β”‚ ab β”‚ df β”‚ β”‚ df β”‚ β”‚ β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## materialize[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#materialize "Direct link to materialize") Introduced in: v1.1.0 Turns a constant into a full column containing a single value. Full columns and constants are represented differently in memory. Functions usually execute different code for normal and constant arguments, although the result should typically be the same. This function can be used to debug this behavior. **Syntax** ``` materialize(x) ``` **Arguments** - `x` β€” A constant. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns a full column containing the constant value. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **Usage example** ``` -- In the example below the `countMatches` function expects a constant second argument. -- This behaviour can be debugged by using the `materialize` function to turn a constant into a full column, -- verifying that the function throws an error for a non-constant argument. SELECT countMatches('foobarfoo', 'foo'); SELECT countMatches('foobarfoo', materialize('foo')); ``` ``` 2 Code: 44. DB::Exception: Received from localhost:9000. DB::Exception: Illegal type of argument #2 'pattern' of function countMatches, expected constant String, got String ``` ## minSampleSizeContinuous[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#minSampleSizeContinuous "Direct link to minSampleSizeContinuous") Introduced in: v23.10.0 Calculates the minimum required sample size for an A/B test comparing means of a continuous metric in two samples. Uses the formula described in [this article](https://towardsdatascience.com/required-sample-size-for-a-b-testing-6f6608dd330a). Assumes equal sizes of treatment and control groups. Returns the required sample size for one group (i.e. the sample size required for the whole experiment is twice the returned value). Also assumes equal variance of the test metric in treatment and control groups. **Syntax** ``` minSampleSizeContinuous(baseline, sigma, mde, power, alpha) ``` **Aliases**: `minSampleSizeContinous` **Arguments** - `baseline` β€” Baseline value of a metric. [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) - `sigma` β€” Baseline standard deviation of a metric. [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) - `mde` β€” Minimum detectable effect (MDE) as percentage of the baseline value (e.g. for a baseline value 112.25 the MDE 0.03 means an expected change to 112.25 Β± 112.25\*0.03). [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) - `power` β€” Required statistical power of a test (1 - probability of Type II error). [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) - `alpha` β€” Required significance level of a test (probability of Type I error). [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) **Returned value** Returns a named Tuple with 3 elements: `minimum_sample_size`, `detect_range_lower` and `detect_range_upper`. These are respectively: the required sample size, the lower bound of the range of values not detectable with the returned required sample size, calculated as `baseline * (1 - mde)`, and the upper bound of the range of values not detectable with the returned required sample size, calculated as `baseline * (1 + mde)` (Float64). [`Tuple(Float64, Float64, Float64)`](https://clickhouse.com/docs/sql-reference/data-types/tuple) **Examples** **minSampleSizeContinuous** ``` SELECT minSampleSizeContinuous(112.25, 21.1, 0.03, 0.80, 0.05) AS sample_size ``` ``` (616.2931945826209,108.8825,115.6175) ``` ## minSampleSizeConversion[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#minSampleSizeConversion "Direct link to minSampleSizeConversion") Introduced in: v22.6.0 Calculates minimum required sample size for an A/B test comparing conversions (proportions) in two samples. Uses the formula described in [this article](https://towardsdatascience.com/required-sample-size-for-a-b-testing-6f6608dd330a). Assumes equal sizes of treatment and control groups. Returns the sample size required for one group (i.e. the sample size required for the whole experiment is twice the returned value). **Syntax** ``` minSampleSizeConversion(baseline, mde, power, alpha) ``` **Arguments** - `baseline` β€” Baseline conversion. [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) - `mde` β€” Minimum detectable effect (MDE) as percentage points (e.g. for a baseline conversion 0.25 the MDE 0.03 means an expected change to 0.25 Β± 0.03). [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) - `power` β€” Required statistical power of a test (1 - probability of Type II error). [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) - `alpha` β€” Required significance level of a test (probability of Type I error). [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) **Returned value** Returns a named Tuple with 3 elements: `minimum_sample_size`, `detect_range_lower`, `detect_range_upper`. These are, respectively: the required sample size, the lower bound of the range of values not detectable with the returned required sample size, calculated as `baseline - mde`, the upper bound of the range of values not detectable with the returned required sample size, calculated as `baseline + mde`. [`Tuple(Float64, Float64, Float64)`](https://clickhouse.com/docs/sql-reference/data-types/tuple) **Examples** **minSampleSizeConversion** ``` SELECT minSampleSizeConversion(0.25, 0.03, 0.80, 0.05) AS sample_size ``` ``` (3396.077603219163,0.22,0.28) ``` ## neighbor[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#neighbor "Direct link to neighbor") Introduced in: v20.1.0 Returns a value from a column at a specified offset from the current row. This function is deprecated and error-prone because it operates on the physical order of data blocks which may not correspond to the logical order expected by users. Consider using proper window functions instead. The function can be enabled by setting `allow_deprecated_error_prone_window_functions = 1`. **Syntax** ``` neighbor(column, offset[, default_value]) ``` **Arguments** - `column` β€” The source column. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) - `offset` β€” The offset from the current row. Positive values look forward, negative values look backward. [`Integer`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) - `default_value` β€” Optional. The value to return if the offset goes beyond the data bounds. If not specified, uses the default value for the column type. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns a value from the specified offset, or default if out of bounds. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **Usage example** ``` SELECT number, neighbor(number, 2) FROM system.numbers LIMIT 10; ``` ``` β”Œβ”€number─┬─neighbor(number, 2)─┐ β”‚ 0 β”‚ 2 β”‚ β”‚ 1 β”‚ 3 β”‚ β”‚ 2 β”‚ 4 β”‚ β”‚ 3 β”‚ 5 β”‚ β”‚ 4 β”‚ 6 β”‚ β”‚ 5 β”‚ 7 β”‚ β”‚ 6 β”‚ 8 β”‚ β”‚ 7 β”‚ 9 β”‚ β”‚ 8 β”‚ 0 β”‚ β”‚ 9 β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **With default value** ``` SELECT number, neighbor(number, 2, 999) FROM system.numbers LIMIT 10; ``` ``` β”Œβ”€number─┬─neighbor(number, 2, 999)─┐ β”‚ 0 β”‚ 2 β”‚ β”‚ 1 β”‚ 3 β”‚ β”‚ 2 β”‚ 4 β”‚ β”‚ 3 β”‚ 5 β”‚ β”‚ 4 β”‚ 6 β”‚ β”‚ 5 β”‚ 7 β”‚ β”‚ 6 β”‚ 8 β”‚ β”‚ 7 β”‚ 9 β”‚ β”‚ 8 β”‚ 999 β”‚ β”‚ 9 β”‚ 999 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## normalizeQuery[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#normalizeQuery "Direct link to normalizeQuery") Introduced in: v20.8.0 Replaces literals, sequences of literals and complex aliases (containing whitespace, more than two digits or at least 36 bytes long such as UUIDs) with placeholder `?`. **Syntax** ``` normalizeQuery(x) ``` **Arguments** - `x` β€” Sequence of characters. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the given sequence of characters with placeholders. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT normalizeQuery('[1, 2, 3, x]') AS query ``` ``` β”Œβ”€query────┐ β”‚ [?.., x] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## normalizeQueryKeepNames[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#normalizeQueryKeepNames "Direct link to normalizeQueryKeepNames") Introduced in: v21.2.0 Replaces literals and sequences of literals with placeholder `?` but does not replace complex aliases (containing whitespace, more than two digits or at least 36 bytes long such as UUIDs). This helps better analyze complex query logs. **Syntax** ``` normalizeQueryKeepNames(x) ``` **Arguments** - `x` β€” Sequence of characters. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the given sequence of characters with placeholders. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT normalizeQuery('SELECT 1 AS aComplexName123'), normalizeQueryKeepNames('SELECT 1 AS aComplexName123') ``` ``` β”Œβ”€normalizeQuery('SELECT 1 AS aComplexName123')─┬─normalizeQueryKeepNames('SELECT 1 AS aComplexName123')─┐ β”‚ SELECT ? AS `?` β”‚ SELECT ? AS aComplexName123 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## normalizedQueryHash[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#normalizedQueryHash "Direct link to normalizedQueryHash") Introduced in: v20.8.0 Returns identical 64 bit hash values without the values of literals for similar queries. Can be helpful in analyzing query logs. **Syntax** ``` normalizedQueryHash(x) ``` **Arguments** - `x` β€” Sequence of characters. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns a 64 bit hash value. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT normalizedQueryHash('SELECT 1 AS `xyz`') != normalizedQueryHash('SELECT 1 AS `abc`') AS res ``` ``` β”Œβ”€res─┐ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”˜ ``` ## normalizedQueryHashKeepNames[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#normalizedQueryHashKeepNames "Direct link to normalizedQueryHashKeepNames") Introduced in: v21.2.0 Like [`normalizedQueryHash`](https://clickhouse.com/docs/sql-reference/functions/other-functions#normalizedQueryHash) it returns identical 64 bit hash values without the values of literals for similar queries, but it does not replace complex aliases (containing whitespace, more than two digits or at least 36 bytes long such as UUIDs) with a placeholder before hashing. Can be helpful in analyzing query logs. **Syntax** ``` normalizedQueryHashKeepNames(x) ``` **Arguments** - `x` β€” Sequence of characters. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns a 64 bit hash value. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT normalizedQueryHash('SELECT 1 AS `xyz123`') != normalizedQueryHash('SELECT 1 AS `abc123`') AS normalizedQueryHash; SELECT normalizedQueryHashKeepNames('SELECT 1 AS `xyz123`') != normalizedQueryHashKeepNames('SELECT 1 AS `abc123`') AS normalizedQueryHashKeepNames; ``` ``` β”Œβ”€normalizedQueryHash─┐ β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€normalizedQueryHashKeepNames─┐ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## parseReadableSize[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#parseReadableSize "Direct link to parseReadableSize") Introduced in: v24.6.0 Given a string containing a byte size and `B`, `KiB`, `KB`, `MiB`, `MB`, etc. as a unit (i.e. [ISO/IEC 80000-13](https://en.wikipedia.org/wiki/ISO/IEC_80000) or decimal byte unit), this function returns the corresponding number of bytes. If the function is unable to parse the input value, it throws an exception. The inverse operations of this function are [`formatReadableSize`](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatReadableSize) and [`formatReadableDecimalSize`](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatReadableDecimalSize). **Syntax** ``` parseReadableSize(x) ``` **Arguments** - `x` β€” Readable size with ISO/IEC 80000-13 or decimal byte unit. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the number of bytes, rounded up to the nearest integer. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT arrayJoin(['1 B', '1 KiB', '3 MB', '5.314 KiB']) AS readable_sizes, parseReadableSize(readable_sizes) AS sizes; ``` ``` β”Œβ”€readable_sizes─┬───sizes─┐ β”‚ 1 B β”‚ 1 β”‚ β”‚ 1 KiB β”‚ 1024 β”‚ β”‚ 3 MB β”‚ 3000000 β”‚ β”‚ 5.314 KiB β”‚ 5442 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## parseReadableSizeOrNull[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#parseReadableSizeOrNull "Direct link to parseReadableSizeOrNull") Introduced in: v24.6.0 Given a string containing a byte size and `B`, `KiB`, `KB`, `MiB`, `MB`, etc. as a unit (i.e. [ISO/IEC 80000-13](https://en.wikipedia.org/wiki/ISO/IEC_80000) or decimal byte unit), this function returns the corresponding number of bytes. If the function is unable to parse the input value, it returns `NULL`. The inverse operations of this function are [`formatReadableSize`](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatReadableSize) and [`formatReadableDecimalSize`](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatReadableDecimalSize). **Syntax** ``` parseReadableSizeOrNull(x) ``` **Arguments** - `x` β€” Readable size with ISO/IEC 80000-13 or decimal byte unit. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the number of bytes, rounded up to the nearest integer, or `NULL` if unable to parse the input [`Nullable(UInt64)`](https://clickhouse.com/docs/sql-reference/data-types/nullable) **Examples** **Usage example** ``` SELECT arrayJoin(['1 B', '1 KiB', '3 MB', '5.314 KiB', 'invalid']) AS readable_sizes, parseReadableSizeOrNull(readable_sizes) AS sizes; ``` ``` β”Œβ”€readable_sizes─┬───sizes─┐ β”‚ 1 B β”‚ 1 β”‚ β”‚ 1 KiB β”‚ 1024 β”‚ β”‚ 3 MB β”‚ 3000000 β”‚ β”‚ 5.314 KiB β”‚ 5442 β”‚ β”‚ invalid β”‚ ᴺᡁᴸᴸ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## parseReadableSizeOrZero[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#parseReadableSizeOrZero "Direct link to parseReadableSizeOrZero") Introduced in: v24.6.0 Given a string containing a byte size and `B`, `KiB`, `KB`, `MiB`, `MB`, etc. as a unit (i.e. [ISO/IEC 80000-13](https://en.wikipedia.org/wiki/ISO/IEC_80000) or decimal byte unit), this function returns the corresponding number of bytes. If the function is unable to parse the input value, it returns `0`. The inverse operations of this function are [`formatReadableSize`](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatReadableSize) and [`formatReadableDecimalSize`](https://clickhouse.com/docs/sql-reference/functions/other-functions#formatReadableDecimalSize). **Syntax** ``` parseReadableSizeOrZero(x) ``` **Arguments** - `x` β€” Readable size with ISO/IEC 80000-13 or decimal byte unit. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns the number of bytes, rounded up to the nearest integer, or `0` if unable to parse the input. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT arrayJoin(['1 B', '1 KiB', '3 MB', '5.314 KiB', 'invalid']) AS readable_sizes, parseReadableSizeOrZero(readable_sizes) AS sizes; ``` ``` β”Œβ”€readable_sizes─┬───sizes─┐ β”‚ 1 B β”‚ 1 β”‚ β”‚ 1 KiB β”‚ 1024 β”‚ β”‚ 3 MB β”‚ 3000000 β”‚ β”‚ 5.314 KiB β”‚ 5442 β”‚ β”‚ invalid β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## parseTimeDelta[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#parseTimeDelta "Direct link to parseTimeDelta") Introduced in: v22.7.0 Parse a sequence of numbers followed by something resembling a time unit. The time delta string uses these time unit specifications: - `years`, `year`, `yr`, `y` - `months`, `month`, `mo` - `weeks`, `week`, `w` - `days`, `day`, `d` - `hours`, `hour`, `hr`, `h` - `minutes`, `minute`, `min`, `m` - `seconds`, `second`, `sec`, `s` - `milliseconds`, `millisecond`, `millisec`, `ms` - `microseconds`, `microsecond`, `microsec`, `ΞΌs`, `Β΅s`, `us` - `nanoseconds`, `nanosecond`, `nanosec`, `ns` Multiple time units can be combined with separators (space, `;`, `-`, `+`, `,`, `:`). The length of years and months are approximations: year is 365 days, month is 30.5 days. **Syntax** ``` parseTimeDelta(timestr) ``` **Arguments** - `timestr` β€” A sequence of numbers followed by something resembling a time unit. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** The number of seconds. [`Float64`](https://clickhouse.com/docs/sql-reference/data-types/float) **Examples** **Usage example** ``` SELECT parseTimeDelta('11s+22min') ``` ``` β”Œβ”€parseTimeDelta('11s+22min')─┐ β”‚ 1331 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Complex time units** ``` SELECT parseTimeDelta('1yr2mo') ``` ``` β”Œβ”€parseTimeDelta('1yr2mo')─┐ β”‚ 36806400 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## partitionId[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#partitionId "Direct link to partitionId") Introduced in: v21.4.0 Computes the [partition ID](https://clickhouse.com/docs/engines/table-engines/mergetree-family/custom-partitioning-key). Note This function is slow and should not be called for large numbers of rows. **Syntax** ``` partitionId(column1[, column2, ...]) ``` **Aliases**: `partitionID` **Arguments** - `column1, column2, ...` β€” Column for which to return the partition ID. **Returned value** Returns the partition ID that the row belongs to. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` DROP TABLE IF EXISTS tab; CREATE TABLE tab ( i int, j int ) ENGINE = MergeTree PARTITION BY i ORDER BY tuple(); INSERT INTO tab VALUES (1, 1), (1, 2), (1, 3), (2, 4), (2, 5), (2, 6); SELECT i, j, partitionId(i), _partition_id FROM tab ORDER BY i, j; ``` ``` β”Œβ”€i─┬─j─┬─partitionId(i)─┬─_partition_id─┐ β”‚ 1 β”‚ 1 β”‚ 1 β”‚ 1 β”‚ β”‚ 1 β”‚ 2 β”‚ 1 β”‚ 1 β”‚ β”‚ 1 β”‚ 3 β”‚ 1 β”‚ 1 β”‚ β”‚ 2 β”‚ 4 β”‚ 2 β”‚ 2 β”‚ β”‚ 2 β”‚ 5 β”‚ 2 β”‚ 2 β”‚ β”‚ 2 β”‚ 6 β”‚ 2 β”‚ 2 β”‚ β””β”€β”€β”€β”΄β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## queryID[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#queryID "Direct link to queryID") Introduced in: v21.9.0 Returns the ID of the current query. Other parameters of a query can be extracted from field `query_id` in the [`system.query_log`](https://clickhouse.com/docs/operations/system-tables/query_log) table. In contrast to [`initialQueryID`](https://clickhouse.com/docs/sql-reference/functions/other-functions#initialQueryID) function, `queryID` can return different results on different shards. **Syntax** ``` queryID() ``` **Aliases**: `query_id` **Arguments** - None. **Returned value** Returns the ID of the current query. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` CREATE TABLE tmp (str String) ENGINE = Log; INSERT INTO tmp (*) VALUES ('a'); SELECT count(DISTINCT t) FROM (SELECT queryID() AS t FROM remote('127.0.0.{1..3}', currentDatabase(), 'tmp') GROUP BY queryID()); ``` ``` β”Œβ”€count(DISTINCT t)─┐ β”‚ 3 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## revision[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#revision "Direct link to revision") Introduced in: v22.7.0 Returns the current ClickHouse server revision. **Syntax** ``` revision() ``` **Arguments** - None. **Returned value** Returns the current ClickHouse server revision. [`UInt32`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT revision() ``` ``` β”Œβ”€revision()─┐ β”‚ 54485 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## rowNumberInAllBlocks[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#rowNumberInAllBlocks "Direct link to rowNumberInAllBlocks") Introduced in: v1.1.0 Returns a unique row number for each row processed. **Syntax** ``` rowNumberInAllBlocks() ``` **Arguments** - None. **Returned value** Returns the ordinal number of the row in the data block starting from `0`. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT rowNumberInAllBlocks() FROM ( SELECT * FROM system.numbers_mt LIMIT 10 ) SETTINGS max_block_size = 2 ``` ``` β”Œβ”€rowNumberInAllBlocks()─┐ β”‚ 0 β”‚ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€rowNumberInAllBlocks()─┐ β”‚ 4 β”‚ β”‚ 5 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€rowNumberInAllBlocks()─┐ β”‚ 2 β”‚ β”‚ 3 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€rowNumberInAllBlocks()─┐ β”‚ 6 β”‚ β”‚ 7 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€rowNumberInAllBlocks()─┐ β”‚ 8 β”‚ β”‚ 9 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## rowNumberInBlock[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#rowNumberInBlock "Direct link to rowNumberInBlock") Introduced in: v1.1.0 For each [block](https://clickhouse.com/docs/development/architecture#block) processed by `rowNumberInBlock`, returns the number of the current row. The returned number starts from 0 for each block. **Syntax** ``` rowNumberInBlock() ``` **Arguments** - None. **Returned value** Returns the ordinal number of the row in the data block starting from `0`. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT rowNumberInBlock() FROM ( SELECT * FROM system.numbers_mt LIMIT 10 ) SETTINGS max_block_size = 2 ``` ``` β”Œβ”€rowNumberInBlock()─┐ β”‚ 0 β”‚ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€rowNumberInBlock()─┐ β”‚ 0 β”‚ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€rowNumberInBlock()─┐ β”‚ 0 β”‚ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€rowNumberInBlock()─┐ β”‚ 0 β”‚ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€rowNumberInBlock()─┐ β”‚ 0 β”‚ β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## runningAccumulate[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#runningAccumulate "Direct link to runningAccumulate") Introduced in: v1.1.0 Accumulates the states of an aggregate function for each row of a data block. **Syntax** ``` runningAccumulate(agg_state[, grouping]) ``` **Arguments** - `agg_state` β€” State of the aggregate function. [`AggregateFunction`](https://clickhouse.com/docs/sql-reference/data-types/aggregatefunction) - `grouping` β€” Optional. Grouping key. The state of the function is reset if the `grouping` value is changed. It can be any of the supported data types for which the equality operator is defined. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns the accumulated result for each row. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **Usage example with initializeAggregation** ``` WITH initializeAggregation('sumState', number) AS one_row_sum_state SELECT number, finalizeAggregation(one_row_sum_state) AS one_row_sum, runningAccumulate(one_row_sum_state) AS cumulative_sum FROM numbers(5); ``` ``` β”Œβ”€number─┬─one_row_sum─┬─cumulative_sum─┐ β”‚ 0 β”‚ 0 β”‚ 0 β”‚ β”‚ 1 β”‚ 1 β”‚ 1 β”‚ β”‚ 2 β”‚ 2 β”‚ 3 β”‚ β”‚ 3 β”‚ 3 β”‚ 6 β”‚ β”‚ 4 β”‚ 4 β”‚ 10 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## runningConcurrency[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#runningConcurrency "Direct link to runningConcurrency") Introduced in: v21.3.0 Calculates the number of concurrent events. Each event has a start time and an end time. The start time is included in the event, while the end time is excluded. Columns with a start time and an end time must be of the same data type. The function calculates the total number of active (concurrent) events for each event start time. Requirements Events must be ordered by the start time in ascending order. If this requirement is violated the function raises an exception. Every data block is processed separately. If events from different data blocks overlap then they can not be processed correctly. **Syntax** ``` runningConcurrency(start, end) ``` **Arguments** - `start` β€” A column with the start time of events. [`Date`](https://clickhouse.com/docs/sql-reference/data-types/date) or [`DateTime`](https://clickhouse.com/docs/sql-reference/data-types/datetime) or [`DateTime64`](https://clickhouse.com/docs/sql-reference/data-types/datetime64) - `end` β€” A column with the end time of events. [`Date`](https://clickhouse.com/docs/sql-reference/data-types/date) or [`DateTime`](https://clickhouse.com/docs/sql-reference/data-types/datetime) or [`DateTime64`](https://clickhouse.com/docs/sql-reference/data-types/datetime64) **Returned value** Returns the number of concurrent events at each event start time. [`UInt32`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT start, runningConcurrency(start, end) FROM example_table; ``` ``` β”Œβ”€β”€β”€β”€β”€β”€start─┬─runningConcurrency(start, end)─┐ β”‚ 2025-03-03 β”‚ 1 β”‚ β”‚ 2025-03-06 β”‚ 2 β”‚ β”‚ 2025-03-07 β”‚ 3 β”‚ β”‚ 2025-03-11 β”‚ 2 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## runningDifference[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#runningDifference "Direct link to runningDifference") Introduced in: v1.1.0 Calculates the difference between two consecutive row values in the data block. Returns `0` for the first row, and for subsequent rows the difference to the previous row. The result of the function depends on the affected data blocks and the order of data in the block. The order of rows during calculation of `runningDifference()` can differ from the order of rows returned to the user. To prevent that you can create a subquery with [`ORDER BY`](https://clickhouse.com/docs/sql-reference/statements/select/order-by) and call the function from outside the subquery. Please note that the block size affects the result. The internal state of `runningDifference` state is reset for each new block. **Syntax** ``` runningDifference(x) ``` **Arguments** - `x` β€” Column for which to calculate the running difference. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns the difference between consecutive values, with 0 for the first row. **Examples** **Usage example** ``` SELECT EventID, EventTime, runningDifference(EventTime) AS delta FROM ( SELECT EventID, EventTime FROM events WHERE EventDate = '2025-11-24' ORDER BY EventTime ASC LIMIT 5 ); ``` ``` β”Œβ”€EventID─┬───────────EventTime─┬─delta─┐ β”‚ 1106 β”‚ 2025-11-24 00:00:04 β”‚ 0 β”‚ β”‚ 1107 β”‚ 2025-11-24 00:00:05 β”‚ 1 β”‚ β”‚ 1108 β”‚ 2025-11-24 00:00:05 β”‚ 0 β”‚ β”‚ 1109 β”‚ 2025-11-24 00:00:09 β”‚ 4 β”‚ β”‚ 1110 β”‚ 2025-11-24 00:00:10 β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **Block size impact example** ``` SELECT number, runningDifference(number + 1) AS diff FROM numbers(100000) WHERE diff != 1; ``` ``` β”Œβ”€number─┬─diff─┐ β”‚ 0 β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”˜ β”Œβ”€number─┬─diff─┐ β”‚ 65536 β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”˜ ``` ## runningDifferenceStartingWithFirstValue[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#runningDifferenceStartingWithFirstValue "Direct link to runningDifferenceStartingWithFirstValue") Introduced in: v1.1.0 Calculates the difference between consecutive row values in a data block, but unlike [`runningDifference`](https://clickhouse.com/docs/sql-reference/functions/other-functions#runningDifference), it returns the actual value of the first row instead of `0`. Deprecated Only returns differences inside the currently processed data block. Because of this error-prone behavior, the function is deprecated. It is advised to use [window functions](https://clickhouse.com/docs/sql-reference/window-functions) instead. You can use setting `allow_deprecated_error_prone_window_functions` to allow usage of this function. **Syntax** ``` runningDifferenceStartingWithFirstValue(x) ``` **Arguments** - `x` β€” Column for which to calculate the running difference. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns the difference between consecutive values, with the first row's value for the first row. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **Usage example** ``` SELECT number, runningDifferenceStartingWithFirstValue(number) AS diff FROM numbers(5); ``` ``` β”Œβ”€number─┬─diff─┐ β”‚ 0 β”‚ 0 β”‚ β”‚ 1 β”‚ 1 β”‚ β”‚ 2 β”‚ 1 β”‚ β”‚ 3 β”‚ 1 β”‚ β”‚ 4 β”‚ 1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”˜ ``` ## serverUUID[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#serverUUID "Direct link to serverUUID") Introduced in: v20.1.0 Returns the random and unique UUID (v4) generated when the server is first started. The UUID is persisted, i.e. the second, third, etc. server start return the same UUID. **Syntax** ``` serverUUID() ``` **Arguments** - None. **Returned value** Returns the random UUID of the server. [`UUID`](https://clickhouse.com/docs/sql-reference/data-types/uuid) **Examples** **Usage example** ``` SELECT serverUUID(); ``` ``` β”Œβ”€serverUUID()─────────────────────────────┐ β”‚ 7ccc9260-000d-4d5c-a843-5459abaabb5f β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## shardCount[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#shardCount "Direct link to shardCount") Introduced in: v21.9.0 Returns the total number of shards for a distributed query. If a query is not distributed then constant value `0` is returned. **Syntax** ``` shardCount() ``` **Arguments** - None. **Returned value** Returns the total number of shards or `0`. [`UInt32`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` -- See shardNum() example above which also demonstrates shardCount() CREATE TABLE shard_count_example (dummy UInt8) ENGINE=Distributed(test_cluster_two_shards_localhost, system, one, dummy); SELECT shardCount() FROM shard_count_example; ``` ``` β”Œβ”€shardCount()─┐ β”‚ 2 β”‚ β”‚ 2 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## shardNum[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#shardNum "Direct link to shardNum") Introduced in: v21.9.0 Returns the index of a shard which processes a part of data in a distributed query. Indices begin from `1`. If a query is not distributed then a constant value `0` is returned. **Syntax** ``` shardNum() ``` **Arguments** - None. **Returned value** Returns the shard index or a constant `0`. [`UInt32`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` CREATE TABLE shard_num_example (dummy UInt8) ENGINE=Distributed(test_cluster_two_shards_localhost, system, one, dummy); SELECT dummy, shardNum(), shardCount() FROM shard_num_example; ``` ``` β”Œβ”€dummy─┬─shardNum()─┬─shardCount()─┐ β”‚ 0 β”‚ 1 β”‚ 2 β”‚ β”‚ 0 β”‚ 2 β”‚ 2 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## showCertificate[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#showCertificate "Direct link to showCertificate") Introduced in: v22.6.0 Shows information about the current server's Secure Sockets Layer (SSL) certificate if it has been configured. See [Configuring TLS](https://clickhouse.com/docs/guides/sre/tls/configuring-tls) for more information on how to configure ClickHouse to use OpenSSL certificates to validate connections. **Syntax** ``` showCertificate() ``` **Arguments** - None. **Returned value** Returns map of key-value pairs relating to the configured SSL certificate. [`Map(String, String)`](https://clickhouse.com/docs/sql-reference/data-types/map) **Examples** **Usage example** ``` SELECT showCertificate() FORMAT LineAsString; ``` ``` {'version':'1','serial_number':'2D9071D64530052D48308473922C7ADAFA85D6C5','signature_algo':'sha256WithRSAEncryption','issuer':'/CN=marsnet.local CA','not_before':'May 7 17:01:21 2024 GMT','not_after':'May 7 17:01:21 2025 GMT','subject':'/CN=chnode1','pkey_algo':'rsaEncryption'} ``` ## sleep[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#sleep "Direct link to sleep") Introduced in: v1.1.0 Pauses the execution of a query by the specified number of seconds. The function is primarily used for testing and debugging purposes. The `sleep()` function should generally not be used in production environments, as it can negatively impact query performance and system responsiveness. However, it can be useful in the following scenarios: 1. **Testing**: When testing or benchmarking ClickHouse, you may want to simulate delays or introduce pauses to observe how the system behaves under certain conditions. 2. **Debugging**: If you need to examine the state of the system or the execution of a query at a specific point in time, you can use `sleep()` to introduce a pause, allowing you to inspect or collect relevant information. 3. **Simulation**: In some cases, you may want to simulate real-world scenarios where delays or pauses occur, such as network latency or external system dependencies. Note It's important to use the `sleep()` function judiciously and only when necessary, as it can potentially impact the overall performance and responsiveness of your ClickHouse system. For security reasons, the function can only be executed in the default user profile (with `allow_sleep` enabled). **Syntax** ``` sleep(seconds) ``` **Arguments** - `seconds` β€” The number of seconds to pause the query execution to a maximum of 3 seconds. It can be a floating-point value to specify fractional seconds. [`const UInt*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`const Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) **Returned value** Returns `0`. [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` -- This query will pause for 2 seconds before completing. -- During this time, no results will be returned, and the query will appear to be hanging or unresponsive. SELECT sleep(2); ``` ``` β”Œβ”€sleep(2)─┐ β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ 1 row in set. Elapsed: 2.012 sec. ``` ## sleepEachRow[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#sleepEachRow "Direct link to sleepEachRow") Introduced in: v1.1.0 Pauses the execution of a query for a specified number of seconds for each row in the result set. The `sleepEachRow()` function is primarily used for testing and debugging purposes, similar to the [`sleep()`](https://clickhouse.com/docs/sql-reference/functions/other-functions#sleep) function. It allows you to simulate delays or introduce pauses in the processing of each row, which can be useful in scenarios such as: 1. **Testing**: When testing or benchmarking ClickHouse's performance under specific conditions, you can use `sleepEachRow()` to simulate delays or introduce pauses for each row processed. 2. **Debugging**: If you need to examine the state of the system or the execution of a query for each row processed, you can use `sleepEachRow()` to introduce pauses, allowing you to inspect or collect relevant information. 3. **Simulation**: In some cases, you may want to simulate real-world scenarios where delays or pauses occur for each row processed, such as when dealing with external systems or network latencies. Note Like the `sleep()` function, it's important to use `sleepEachRow()` judiciously and only when necessary, as it can significantly impact the overall performance and responsiveness of your ClickHouse system, especially when dealing with large result sets. **Syntax** ``` sleepEachRow(seconds) ``` **Arguments** - `seconds` β€” The number of seconds to pause the query execution for each row in the result set to a maximum of 3 seconds. It can be a floating-point value to specify fractional seconds. [`const UInt*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`const Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) **Returned value** Returns `0` for each row. [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` -- The output will be delayed, with a 0.5-second pause between each row. SELECT number, sleepEachRow(0.5) FROM system.numbers LIMIT 5; ``` ``` β”Œβ”€number─┬─sleepEachRow(0.5)─┐ β”‚ 0 β”‚ 0 β”‚ β”‚ 1 β”‚ 0 β”‚ β”‚ 2 β”‚ 0 β”‚ β”‚ 3 β”‚ 0 β”‚ β”‚ 4 β”‚ 0 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## structureToCapnProtoSchema[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#structureToCapnProtoSchema "Direct link to structureToCapnProtoSchema") Introduced in: v23.8.0 Function that converts ClickHouse table structure to CapnProto format schema **Syntax** ``` structureToCapnProtoSchema(table_structure, message) ``` **Arguments** - None. **Returned value** **Examples** **random** ``` SELECT structureToCapnProtoSchema('s String, x UInt32', 'MessageName') format TSVRaw ``` ``` struct MessageName { s @0 : Data; x @1 : UInt32; } ``` ## structureToProtobufSchema[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#structureToProtobufSchema "Direct link to structureToProtobufSchema") Introduced in: v23.8.0 Converts a ClickHouse table structure to Protobuf format schema. This function takes a ClickHouse table structure definition and converts it into a Protocol Buffers (Protobuf) schema definition in proto3 syntax. This is useful for generating Protobuf schemas that match your ClickHouse table structures for data interchange. **Syntax** ``` structureToProtobufSchema(structure, message_name) ``` **Arguments** - `structure` β€” ClickHouse table structure definition as a string (e.g., 'column1 Type1, column2 Type2'). [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `message_name` β€” Name for the Protobuf message type in the generated schema. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Returned value** Returns a Protobuf schema definition in proto3 syntax that corresponds to the input ClickHouse structure. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Converting ClickHouse structure to Protobuf schema** ``` SELECT structureToProtobufSchema('s String, x UInt32', 'MessageName') FORMAT TSVRaw; ``` ``` syntax = "proto3"; message MessageName { bytes s = 1; uint32 x = 2; } ``` ## tcpPort[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#tcpPort "Direct link to tcpPort") Introduced in: v20.12.0 Returns the [native interface](https://clickhouse.com/docs/interfaces/tcp) TCP port number listened to by the server. If executed in the context of a distributed table, this function generates a normal column with values relevant to each shard. Otherwise it produces a constant value. **Syntax** ``` tcpPort() ``` **Arguments** - None. **Returned value** Returns the TCP port number. [`UInt16`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT tcpPort() ``` ``` β”Œβ”€tcpPort()─┐ β”‚ 9000 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## throwIf[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#throwIf "Direct link to throwIf") Introduced in: v1.1.0 Throw an exception if argument x is true. To use the `error_code` argument, configuration parameter `allow_custom_error_code_in_throw` must be enabled. **Syntax** ``` throwIf(x[, message[, error_code]]) ``` **Arguments** - `x` β€” The condition to check. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) - `message` β€” Optional. Custom error message. [`const String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `error_code` β€” Optional. Custom error code. [`const Int8/16/32`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Returned value** Returns `0` if the condition is false, throws an exception if the condition is true. [`UInt8`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT throwIf(number = 3, 'Too many') FROM numbers(10); ``` ``` ↙ Progress: 0.00 rows, 0.00 B (0.00 rows/s., 0.00 B/s.) Received exception from server (version 19.14.1): Code: 395. DB::Exception: Received from localhost:9000. DB::Exception: Too many. ``` ## toColumnTypeName[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#toColumnTypeName "Direct link to toColumnTypeName") Introduced in: v1.1.0 Returns the internal name of the data type of the given value. Unlike function [`toTypeName`](https://clickhouse.com/docs/sql-reference/functions/other-functions#toTypeName), the returned data type potentially includes internal wrapper columns like `Const` and `LowCardinality`. **Syntax** ``` toColumnTypeName(value) ``` **Arguments** - `value` β€” Value for which to return the internal data type. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns the internal data type used to represent the value. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT toColumnTypeName(CAST('2025-01-01 01:02:03' AS DateTime)); ``` ``` β”Œβ”€toColumnTypeName(CAST('2025-01-01 01:02:03', 'DateTime'))─┐ β”‚ Const(UInt32) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## toTypeName[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#toTypeName "Direct link to toTypeName") Introduced in: v1.1.0 Returns the type name of the passed argument. If `NULL` is passed, the function returns type `Nullable(Nothing)`, which corresponds to ClickHouse's internal `NULL` representation. **Syntax** ``` toTypeName(x) ``` **Arguments** - `x` β€” A value of arbitrary type. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns the data type name of the input value. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT toTypeName(123) ``` ``` β”Œβ”€toTypeName(123)─┐ β”‚ UInt8 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## transactionID[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#transactionID "Direct link to transactionID") Introduced in: v22.6.0 Not supported in ClickHouse Cloud Returns the ID of a transaction. Note This function is part of an experimental feature set. Enable experimental transaction support by adding this setting to your [configuration](https://clickhouse.com/docs/operations/configuration-files): ``` <clickhouse> <allow_experimental_transactions>1</allow_experimental_transactions> </clickhouse> ``` For more information see the page [Transactional (ACID) support](https://clickhouse.com/docs/guides/developer/transactional#transactions-commit-and-rollback). **Syntax** ``` transactionID() ``` **Arguments** - None. **Returned value** Returns a tuple consisting of `start_csn`, `local_tid` and `host_id`. - `start_csn`: Global sequential number, the newest commit timestamp that was seen when this transaction began. - `local_tid`: Local sequential number that is unique for each transaction started by this host within a specific start\_csn. - `host_id`: UUID of the host that has started this transaction. [`Tuple(UInt64, UInt64, UUID)`](https://clickhouse.com/docs/sql-reference/data-types/tuple) **Examples** **Usage example** ``` BEGIN TRANSACTION; SELECT transactionID(); ROLLBACK; ``` ``` β”Œβ”€transactionID()────────────────────────────────┐ β”‚ (32,34,'0ee8b069-f2bb-4748-9eae-069c85b5252b') β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## transactionLatestSnapshot[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#transactionLatestSnapshot "Direct link to transactionLatestSnapshot") Introduced in: v22.6.0 Not supported in ClickHouse Cloud Returns the newest snapshot (Commit Sequence Number) of a [transaction](https://clickhouse.com/docs/guides/developer/transactional#transactions-commit-and-rollback) that is available for reading. Note This function is part of an experimental feature set. Enable experimental transaction support by adding this setting to your configuration: ``` <clickhouse> <allow_experimental_transactions>1</allow_experimental_transactions> </clickhouse> ``` For more information see the page [Transactional (ACID) support](https://clickhouse.com/docs/guides/developer/transactional#transactions-commit-and-rollback). **Syntax** ``` transactionLatestSnapshot() ``` **Arguments** - None. **Returned value** Returns the latest snapshot (CSN) of a transaction. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` BEGIN TRANSACTION; SELECT transactionLatestSnapshot(); ROLLBACK; ``` ``` β”Œβ”€transactionLatestSnapshot()─┐ β”‚ 32 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## transactionOldestSnapshot[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#transactionOldestSnapshot "Direct link to transactionOldestSnapshot") Introduced in: v22.6.0 Not supported in ClickHouse Cloud Returns the oldest snapshot (Commit Sequence Number) that is visible for some running [transaction](https://clickhouse.com/docs/guides/developer/transactional#transactions-commit-and-rollback). Note This function is part of an experimental feature set. Enable experimental transaction support by adding this setting to your configuration: ``` <clickhouse> <allow_experimental_transactions>1</allow_experimental_transactions> </clickhouse> ``` For more information see the page [Transactional (ACID) support](https://clickhouse.com/docs/guides/developer/transactional#transactions-commit-and-rollback). **Syntax** ``` transactionOldestSnapshot() ``` **Arguments** - None. **Returned value** Returns the oldest snapshot (CSN) of a transaction. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` BEGIN TRANSACTION; SELECT transactionOldestSnapshot(); ROLLBACK; ``` ``` β”Œβ”€transactionOldestSnapshot()─┐ β”‚ 32 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## transform[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#transform "Direct link to transform") Introduced in: v1.1.0 Transforms a value according to the explicitly defined mapping of some elements to other elements. There are two variations of this function: - `transform(x, array_from, array_to, default)` - transforms `x` using mapping arrays with a default value for unmatched elements - `transform(x, array_from, array_to)` - same transformation but returns the original `x` if no match is found The function searches for `x` in `array_from` and returns the corresponding element from `array_to` at the same index. If `x` is not found in `array_from`, it returns either the `default` value (4-parameter version) or the original `x` (3-parameter version). If multiple matching elements exist in `array_from`, it returns the element corresponding to the first match. Requirements: - `array_from` and `array_to` must have the same number of elements - For 4-parameter version: `transform(T, Array(T), Array(U), U) -> U` where `T` and `U` can be different compatible types - For 3-parameter version: `transform(T, Array(T), Array(T)) -> T` where all types must be the same **Syntax** ``` transform(x, array_from, array_to[, default]) ``` **Arguments** - `x` β€” Value to transform. [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) or [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`Date`](https://clickhouse.com/docs/sql-reference/data-types/date) or [`DateTime`](https://clickhouse.com/docs/sql-reference/data-types/datetime) - `array_from` β€” Constant array of values to search for matches. [`Array((U)Int*)`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Array(Decimal)`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Array(Float*)`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Array(String)`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Array(Date)`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Array(DateTime)`](https://clickhouse.com/docs/sql-reference/data-types/array) - `array_to` β€” Constant array of values to return for corresponding matches in `array_from`. [`Array((U)Int*)`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Array(Decimal)`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Array(Float*)`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Array(String)`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Array(Date)`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Array(DateTime)`](https://clickhouse.com/docs/sql-reference/data-types/array) - `default` β€” Optional. Value to return if `x` is not found in `array_from`. If omitted, returns x unchanged. [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) or [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`Date`](https://clickhouse.com/docs/sql-reference/data-types/date) or [`DateTime`](https://clickhouse.com/docs/sql-reference/data-types/datetime) **Returned value** Returns the corresponding value from `array_to` if x matches an element in `array_from`, otherwise returns default (if provided) or x (if default not provided). [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **transform(T, Array(T), Array(U), U) -\> U** ``` SELECT transform(SearchEngineID, [2, 3], ['Yandex', 'Google'], 'Other') AS title, count() AS c FROM test.hits WHERE SearchEngineID != 0 GROUP BY title ORDER BY c DESC ``` ``` β”Œβ”€title─────┬──────c─┐ β”‚ Yandex β”‚ 498635 β”‚ β”‚ Google β”‚ 229872 β”‚ β”‚ Other β”‚ 104472 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` **transform(T, Array(T), Array(T)) -\> T** ``` SELECT transform(domain(Referer), ['yandex.ru', 'google.ru', 'vkontakte.ru'], ['www.yandex', 'example.com', 'vk.com']) AS s, count() AS c FROM test.hits GROUP BY domain(Referer) ORDER BY count() DESC LIMIT 10 ``` ``` β”Œβ”€s──────────────┬───────c─┐ β”‚ β”‚ 2906259 β”‚ β”‚ www.yandex β”‚ 867767 β”‚ β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ.ru β”‚ 313599 β”‚ β”‚ mail.yandex.ru β”‚ 107147 β”‚ β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ.ru β”‚ 100355 β”‚ β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ.ru β”‚ 65040 β”‚ β”‚ news.yandex.ru β”‚ 64515 β”‚ β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ.net β”‚ 59141 β”‚ β”‚ example.com β”‚ 57316 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## uniqThetaIntersect[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#uniqThetaIntersect "Direct link to uniqThetaIntersect") Introduced in: v22.9.0 Two uniqThetaSketch objects to do intersect calculation(set operation ∩), the result is a new uniqThetaSketch. **Syntax** ``` uniqThetaIntersect(uniqThetaSketch,uniqThetaSketch) ``` **Arguments** - `uniqThetaSketch` β€” uniqThetaSketch object. [`Tuple`](https://clickhouse.com/docs/sql-reference/data-types/tuple) or [`Array`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Date`](https://clickhouse.com/docs/sql-reference/data-types/date) or [`DateTime`](https://clickhouse.com/docs/sql-reference/data-types/datetime) or [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) or [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) **Returned value** A new uniqThetaSketch containing the intersect result. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT finalizeAggregation(uniqThetaIntersect(a, b)) AS a_intersect_b, finalizeAggregation(a) AS a_cardinality, finalizeAggregation(b) AS b_cardinality FROM (SELECT arrayReduce('uniqThetaState', [1, 2]) AS a, arrayReduce('uniqThetaState', [2, 3, 4]) AS b); ``` ``` β”Œβ”€a_intersect_b─┬─a_cardinality─┬─b_cardinality─┐ β”‚ 1 β”‚ 2 β”‚ 3 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## uniqThetaNot[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#uniqThetaNot "Direct link to uniqThetaNot") Introduced in: v22.9.0 Two uniqThetaSketch objects to do a\_not\_b calculation(set operation Γ—), the result is a new uniqThetaSketch. **Syntax** ``` uniqThetaNot(uniqThetaSketch,uniqThetaSketch) ``` **Arguments** - `uniqThetaSketch` β€” uniqThetaSketch object. [`Tuple`](https://clickhouse.com/docs/sql-reference/data-types/tuple) or [`Array`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Date`](https://clickhouse.com/docs/sql-reference/data-types/date) or [`DateTime`](https://clickhouse.com/docs/sql-reference/data-types/datetime) or [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) or [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) **Returned value** Returns a new uniqThetaSketch containing the a\_not\_b result. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT finalizeAggregation(uniqThetaNot(a, b)) AS a_not_b, finalizeAggregation(a) AS a_cardinality, finalizeAggregation(b) AS b_cardinality FROM (SELECT arrayReduce('uniqThetaState', [2, 3, 4]) AS a, arrayReduce('uniqThetaState', [1, 2]) AS b); ``` ``` β”Œβ”€a_not_b─┬─a_cardinality─┬─b_cardinality─┐ β”‚ 2 β”‚ 3 β”‚ 2 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## uniqThetaUnion[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#uniqThetaUnion "Direct link to uniqThetaUnion") Introduced in: v22.9.0 Two uniqThetaSketch objects to do union calculation(set operation βˆͺ), the result is a new uniqThetaSketch. **Syntax** ``` uniqThetaUnion(uniqThetaSketch,uniqThetaSketch) ``` **Arguments** - `uniqThetaSketch` β€” uniqThetaSketch object. [`Tuple`](https://clickhouse.com/docs/sql-reference/data-types/tuple) or [`Array`](https://clickhouse.com/docs/sql-reference/data-types/array) or [`Date`](https://clickhouse.com/docs/sql-reference/data-types/date) or [`DateTime`](https://clickhouse.com/docs/sql-reference/data-types/datetime) or [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) or [`(U)Int*`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) or [`Float*`](https://clickhouse.com/docs/sql-reference/data-types/float) or [`Decimal`](https://clickhouse.com/docs/sql-reference/data-types/decimal) **Returned value** Returns a new uniqThetaSketch containing the union result. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT finalizeAggregation(uniqThetaUnion(a, b)) AS a_union_b, finalizeAggregation(a) AS a_cardinality, finalizeAggregation(b) AS b_cardinality FROM (SELECT arrayReduce('uniqThetaState', [1, 2]) AS a, arrayReduce('uniqThetaState', [2, 3, 4]) AS b); ``` ``` β”Œβ”€a_union_b─┬─a_cardinality─┬─b_cardinality─┐ β”‚ 4 β”‚ 2 β”‚ 3 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## uptime[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#uptime "Direct link to uptime") Introduced in: v1.1.0 Returns the server's uptime in seconds. If executed in the context of a distributed table, this function generates a normal column with values relevant to each shard. Otherwise it produces a constant value. **Syntax** ``` uptime() ``` **Arguments** - None. **Returned value** Returns the server uptime in seconds. [`UInt32`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT uptime() AS Uptime ``` ``` β”Œβ”€Uptime─┐ β”‚ 55867 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## variantElement[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#variantElement "Direct link to variantElement") Introduced in: v25.2.0 Extracts a column with specified type from a `Variant` column. **Syntax** ``` variantElement(variant, type_name[, default_value]) ``` **Arguments** - `variant` β€” Variant column. [`Variant`](https://clickhouse.com/docs/sql-reference/data-types/variant) - `type_name` β€” The name of the variant type to extract. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) - `default_value` β€” The default value that will be used if variant doesn't have variant with specified type. Can be any type. Optional. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns a column with the specified variant type extracted from the Variant column. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Examples** **Usage example** ``` CREATE TABLE test (v Variant(UInt64, String, Array(UInt64))) ENGINE = Memory; INSERT INTO test VALUES (NULL), (42), ('Hello, World!'), ([1, 2, 3]); SELECT v, variantElement(v, 'String'), variantElement(v, 'UInt64'), variantElement(v, 'Array(UInt64)') FROM test; ``` ``` β”Œβ”€v─────────────┬─variantElement(v, 'String')─┬─variantElement(v, 'UInt64')─┬─variantElement(v, 'Array(UInt64)')─┐ β”‚ ᴺᡁᴸᴸ β”‚ ᴺᡁᴸᴸ β”‚ ᴺᡁᴸᴸ β”‚ [] β”‚ β”‚ 42 β”‚ ᴺᡁᴸᴸ β”‚ 42 β”‚ [] β”‚ β”‚ Hello, World! β”‚ Hello, World! β”‚ ᴺᡁᴸᴸ β”‚ [] β”‚ β”‚ [1,2,3] β”‚ ᴺᡁᴸᴸ β”‚ ᴺᡁᴸᴸ β”‚ [1,2,3] β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## variantType[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#variantType "Direct link to variantType") Introduced in: v24.2.0 Returns the variant type name for each row of `Variant` column. If row contains NULL, it returns 'None' for it. **Syntax** ``` variantType(variant) ``` **Arguments** - `variant` β€” Variant column. [`Variant`](https://clickhouse.com/docs/sql-reference/data-types/variant) **Returned value** Returns an Enum column with variant type name for each row. [`Enum`](https://clickhouse.com/docs/sql-reference/data-types/enum) **Examples** **Usage example** ``` CREATE TABLE test (v Variant(UInt64, String, Array(UInt64))) ENGINE = Memory; INSERT INTO test VALUES (NULL), (42), ('Hello, World!'), ([1, 2, 3]); SELECT variantType(v) FROM test; ``` ``` β”Œβ”€variantType(v)─┐ β”‚ None β”‚ β”‚ UInt64 β”‚ β”‚ String β”‚ β”‚ Array(UInt64) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## version[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#version "Direct link to version") Introduced in: v1.1.0 Returns the current version of ClickHouse as a string in the form: `major_version.minor_version.patch_version.number_of_commits_since_the_previous_stable_release`. If executed in the context of a distributed table, this function generates a normal column with values relevant to each shard. Otherwise, it produces a constant value. **Syntax** ``` version() ``` **Arguments** - None. **Returned value** Returns the current version of ClickHouse. [`String`](https://clickhouse.com/docs/sql-reference/data-types/string) **Examples** **Usage example** ``` SELECT version() ``` ``` β”Œβ”€version()─┐ β”‚ 24.2.1.1 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## visibleWidth[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#visibleWidth "Direct link to visibleWidth") Introduced in: v1.1.0 Calculates the approximate width when outputting values to the console in text format (tab-separated). This function is used by the system to implement Pretty formats. `NULL` is represented as a string corresponding to `NULL` in Pretty formats. **Syntax** ``` visibleWidth(x) ``` **Arguments** - `x` β€” A value of any data type. [`Any`](https://clickhouse.com/docs/sql-reference/data-types) **Returned value** Returns the approximate width of the value when displayed in text format. [`UInt64`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Calculate visible width of NULL** ``` SELECT visibleWidth(NULL) ``` ``` β”Œβ”€visibleWidth(NULL)─┐ β”‚ 4 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## zookeeperSessionUptime[​](https://clickhouse.com/docs/sql-reference/functions/other-functions#zookeeperSessionUptime "Direct link to zookeeperSessionUptime") Introduced in: v21.11.0 Returns the uptime of the current ZooKeeper session in seconds. **Syntax** ``` zookeeperSessionUptime() ``` **Arguments** - None. **Returned value** Returns the uptime of the current ZooKeeper session in seconds. [`UInt32`](https://clickhouse.com/docs/sql-reference/data-types/int-uint) **Examples** **Usage example** ``` SELECT zookeeperSessionUptime(); ``` ``` β”Œβ”€zookeeperSessionUptime()─┐ β”‚ 286 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ```
Shard89 (laksa)
Root Hash12633450985039531489
Unparsed URLcom,clickhouse!/docs/sql-reference/functions/other-functions s443