Other functions
The function documentation below is generated from the system.functions
system table.
FQDN
Introduced in: v20.1
Returns the fully qualified domain name of the ClickHouse server.
Syntax
Arguments
- None. Returned value
Returns the fully qualified domain name of the ClickHouse server. String
Examples
Usage example
MACNumToString
Introduced in: v1.1
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
Arguments
num
— UInt64 number.UInt64
Returned value
Returns a MAC address in format AA:BB:CC:DD:EE:FF. String
Examples
Usage example
MACStringToNum
Introduced in: v1.1
The inverse function of MACNumToString. If the MAC address has an invalid format, it returns 0.
Syntax
Arguments
s
— MAC address string.String
Returned value
Returns a UInt64 number. UInt64
Examples
Usage example
MACStringToOUI
Introduced in: v1.1
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
Arguments
s
— MAC address string.String
Returned value
First three octets as UInt64 number. UInt64
Examples
Usage example
__filterContains
Introduced in: v25.10
Special function for JOIN runtime filtering.
Syntax
Arguments
filter_name
— Internal name of runtime filter. It is built by BuildRuntimeFilterStep.String
key
— Value of any type that is checked to be present in the filter
Returned value
True if the key was found in the filter Bool
Examples
Example
__patchPartitionID
Introduced in: v25.5
Internal function. Receives the name of a part and a hash of patch part's column names. Returns the name of partition of patch part. The argument must be a correct name of part, the behaviour is undefined otherwise.
Syntax
Arguments
- None. Returned value
Examples
bar
Introduced in: v1.1
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
Arguments
x
— Size to display.(U)Int*
orFloat*
orDecimal
min
— The minimum value.const Int64
max
— The maximum value.const Int64
width
— Optional. The width of the bar in characters. The default is80
.const (U)Int*
orconst Float*
orconst Decimal
Returned value
Returns a unicode-art bar string. String
Examples
Usage example
blockNumber
Introduced in: v1.1
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
Arguments
- None. Returned value
Sequence number of the data block where the row is located. UInt64
Examples
Basic usage
blockSerializedSize
Introduced in: v20.3
Returns the uncompressed size in bytes of a block of values on disk.
Syntax
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
blockSize
Introduced in: v1.1
In ClickHouse, queries are processed in blocks (chunks). This function returns the size (row count) of the block the function is called on.
Syntax
Arguments
- None. Returned value
Returns the number of rows in the current block. UInt64
Examples
Usage example
buildId
Introduced in: v20.5
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
Arguments
- None. Returned value
Returns the build ID. String
Examples
Usage example
byteSize
Introduced in: v21.1
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
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
Multiple arguments
catboostEvaluate
Introduced in: v22.9
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:
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.
- Train a catboost model using libcatboost
See Training and applying models for how to train catboost models from a training data set.
Syntax
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
colorOKLCHToSRGB
Introduced in: v25.7
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.
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
Arguments
tuple
— A tuple of three numeric valuesL
,C
,H
, whereL
is in the range[0...1]
,C >= 0
andH
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 channelx
. Defaults to2.2
.Float64
Returned value
Returns a tuple (R, G, B) representing sRGB color values. Tuple(Float64, Float64, Float64)
Examples
Convert OKLCH to sRGB
colorSRGBToOKLCH
Introduced in: v25.7
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.
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
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 channelx
. Defaults to2.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
connectionId
Introduced in: v21.3
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
Arguments
- None. Returned value
Returns the connection ID of the current client. UInt64
Examples
Usage example
countDigits
Introduced in: v20.8
Returns the number of decimal digits needed to represent a value.
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
You can check decimal overflow for Decimal64
with countDigits(x) > 18
,
although it is slower than isDecimalOverflow
.
Syntax
Arguments
Returned value
Returns the number of digits needed to represent x
. UInt8
Examples
Usage example
currentDatabase
Introduced in: v1.1
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
Arguments
- None. Returned value
Returns the current database name. String
Examples
Usage example
currentProfiles
Introduced in: v21.9
Returns an array of the setting profiles for the current user.
Syntax
Arguments
- None. Returned value
Returns an array of setting profiles for the current user. Array(String)
Examples
Usage example
currentQueryID
Introduced in: v
Returns current Query id.
Syntax
Arguments
- None. Returned value
Examples
Example
currentRoles
Introduced in: v21.9
Returns an array of the roles which are assigned to the current user.
Syntax
Arguments
- None. Returned value
Returns an array of the roles which are assigned to the current user. Array(String)
Examples
Usage example
currentSchemas
Introduced in: v23.7
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
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
currentUser
Introduced in: v20.1
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
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
defaultProfiles
Introduced in: v21.9
Returns an array of default setting profile names for the current user.
Syntax
Arguments
- None. Returned value
Returns an array of default setting profile names for the current user. Array(String)
Examples
Usage example
defaultRoles
Introduced in: v21.9
Returns an array of default roles for the current user.
Syntax
Arguments
- None. Returned value
Returns an array of default roles for the current user. Array(String)
Examples
Usage example
defaultValueOfArgumentType
Introduced in: v1.1
Returns the default value for a given data type. Does not include default values for custom columns set by the user.
Syntax
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
Nullable example
defaultValueOfTypeName
Introduced in: v1.1
Returns the default value for the given type name.
Syntax
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
Nullable example
displayName
Introduced in: v22.11
Returns the value of display_name
from config or the server's Fully Qualified Domain Name (FQDN) if not set.
Syntax
Arguments
- None. Returned value
Returns the value of display_name
from config or server FQDN if not set. String
Examples
Usage example
dumpColumnStructure
Introduced in: v1.1
Outputs a detailed description of the internal structure of a column and its data type.
Syntax
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
enabledProfiles
Introduced in: v21.9
Returns an array of setting profile names which are enabled for the current user.
Syntax
Arguments
- None. Returned value
Returns an array of setting profile names which are enabled for the current user. Array(String)
Examples
Usage example
enabledRoles
Introduced in: v21.9
Returns an array of the roles which are enabled for the current user.
Syntax
Arguments
- None. Returned value
Returns an array of role names which are enabled for the current user. Array(String)
Examples
Usage example
errorCodeToName
Introduced in: v20.12
Returns the textual name of a numeric ClickHouse error code. The mapping from numeric error codes to error names is available here.
Syntax
Arguments
Returned value
Returns the textual name of error_code
. String
Examples
Usage example
file
Introduced in: v21.3
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
Arguments
path
— The path of the file relative to theuser_files_path
. Supports wildcards*
,**
,?
,{abc,def}
and{N..M}
whereN
,M
are numbers and'abc', 'def'
are strings.String
default
— The value returned if the file does not exist or cannot be accessed.String
orNULL
Returned value
Returns the file content as a string. String
Examples
Insert files into a table
filesystemAvailable
Introduced in: v20.1
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
Arguments
disk_name
— Optional. The disk name to find the amount of free space for. If omitted, uses the default disk.String
orFixedString
Returned value
Returns the amount of remaining space available in bytes. UInt64
Examples
Usage example
filesystemCapacity
Introduced in: v20.1
Returns the capacity of the filesystem in bytes. Needs the path to the data directory to be configured.
Syntax
Arguments
disk_name
— Optional. The disk name to get the capacity for. If omitted, uses the default disk.String
orFixedString
Returned value
Returns the capacity of the filesystem in bytes. UInt64
Examples
Usage example
filesystemUnreserved
Introduced in: v22.12
Returns the total amount of free space on the filesystem hosting the database persistence (previously filesystemFree
).
See also filesystemAvailable
.
Syntax
Arguments
disk_name
— Optional. The disk name for which to find the total amount of free space. If omitted, uses the default disk.String
orFixedString
Returned value
Returns the amount of free space in bytes. UInt64
Examples
Usage example
finalizeAggregation
Introduced in: v1.1
Given an aggregation state, this function returns the result of aggregation (or the finalized state when using a -State combinator).
Syntax
Arguments
state
— State of aggregation.AggregateFunction
Returned value
Returns the finalized result of aggregation. Any
Examples
Usage example
Combined with initializeAggregation
formatQuery
Introduced in: v
Returns a formatted, possibly multi-line, version of the given SQL query. Throws in case of a parsing error. [example:multiline]
Syntax
Arguments
query
— The SQL query to be formatted. String
Returned value
The formatted query String
Examples
multiline
formatQueryOrNull
Introduced in: v
Returns a formatted, possibly multi-line, version of the given SQL query. Returns NULL in case of a parsing error. [example:multiline]
Syntax
Arguments
query
— The SQL query to be formatted. String
Returned value
The formatted query String
Examples
multiline
formatQuerySingleLine
Introduced in: v
Like formatQuery() but the returned formatted string contains no line breaks. Throws in case of a parsing error. [example:multiline]
Syntax
Arguments
query
— The SQL query to be formatted. String
Returned value
The formatted query String
Examples
multiline
formatQuerySingleLineOrNull
Introduced in: v
Like formatQuery() but the returned formatted string contains no line breaks. Returns NULL in case of a parsing error. [example:multiline]
Syntax
Arguments
query
— The SQL query to be formatted.String
Returned value
The formatted query String
Examples
multiline
formatReadableDecimalSize
Introduced in: v22.11
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
Arguments
x
— Size in bytes.UInt64
Returned value
Returns a readable, rounded size with suffix as a string. String
Examples
Format file sizes
formatReadableQuantity
Introduced in: v20.10
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
Arguments
x
— A number to format.UInt64
Returned value
Returns a rounded number with suffix as a string. String
Examples
Format numbers with suffixes
formatReadableSize
Introduced in: v1.1
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
Arguments
x
— Size in bytes.UInt64
Returned value
Returns a readable, rounded size with suffix as a string. String
Examples
Format file sizes
formatReadableTimeDelta
Introduced in: v20.12
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
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 thanmaximum_unit
, an exception will be thrown. Default value:seconds
ifmaximum_unit
isseconds
or bigger,nanoseconds
otherwise.const String
Returned value
Returns a time delta as a string. String
Examples
Usage example
With maximum unit
generateRandomStructure
Introduced in: v23.5
Generates random table structure in the format column1_name column1_type, column2_name column2_type, ...
.
Syntax
Arguments
number_of_columns
— The desired number of columns in the resultant table structure. If set to 0 orNull
, 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 toNull
, it is randomly generated.UInt64
Returned value
Randomly generated table structure. String
Examples
Usage example
with specified number of columns
with specified seed
generateSerialID
Introduced in: v
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
Arguments
series_identifier
— Series identifier, (a short constant 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
Returned value
Returns sequential numbers starting from the previous counter value.
Examples
first call
second call
column call
with start value
with start value second call
getClientHTTPHeader
Introduced in: v24.5
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.
allow_get_client_http_header
is requiredThe 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
Arguments
name
— The HTTP header name.String
Returned value
Returns the value of the header. String
Examples
Usage example
getMacro
Introduced in: v20.1
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
Arguments
name
— The name of the macro to retrieve.const String
Returned value
Returns the value of the specified macro. String
Examples
Basic usage
getMaxTableNameLengthForDatabase
Introduced in: v
Returns the maximum table name length in a specified database.
Syntax
Arguments
database_name
— The name of the specified database.String
Returned value
Returns the length of the maximum table name, an Integer
Examples
typical
getMergeTreeSetting
Introduced in: v25.6
Returns the current value of a MergeTree setting.
Syntax
Arguments
setting_name
— The setting name.String
Returned value
Returns the merge tree setting's current value.
Examples
Usage example
getOSKernelVersion
Introduced in: v21.11
Returns a string with the OS kernel version.
Syntax
Arguments
- None. Returned value
Returns the current OS kernel version. String
Examples
Usage example
getServerPort
Introduced in: v21.10
Returns the server's port number for a given protocol.
Syntax
Arguments
port_name
— The name of the port.String
Returned value
Returns the server port number. UInt16
Examples
Usage example
getServerSetting
Introduced in: v25.6
Returns the currently set value, given a server setting name.
Syntax
Arguments
setting_name
— The server setting name.String
Returned value
Returns the server setting's current value. Any
Examples
Usage example
getSetting
Introduced in: v20.7
Returns the current value of a setting.
Syntax
Arguments
setting_Name
— The setting name.const String
Returned value
Returns the setting's current value. Any
Examples
Usage example
getSettingOrDefault
Introduced in: v24.10
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
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
getSizeOfEnumType
Introduced in: v1.1
Returns the number of fields in the given Enum
.
Syntax
Arguments
x
— Value of typeEnum
.Enum
Returned value
Returns the number of fields with Enum
input values. UInt8/16
Examples
Usage example
getSubcolumn
Introduced in: v
Receives the expression or identifier and constant string with the name of subcolumn.
Returns requested subcolumn extracted from the expression.
Syntax
Arguments
- None. Returned value
Examples
getSubcolumn
getTypeSerializationStreams
Introduced in: v22.6
Enumerates stream paths of a data type. This function is intended for developmental use.
Syntax
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
map
globalVariable
Introduced in: v20.5
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
Arguments
name
— Global variable name.String
Returned value
Returns the value of variable name
. Any
Examples
globalVariable
hasColumnInTable
Introduced in: v1.1
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
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
Check a non-existing column
hasThreadFuzzer
Introduced in: v20.6
Returns whether the thread fuzzer is enabled. THis function is only useful for testing and debugging.
Syntax
Arguments
- None. Returned value
Returns whether Thread Fuzzer is effective. UInt8
Examples
Check Thread Fuzzer status
hostName
Introduced in: v20.5
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
Arguments
- None. Returned value
Returns the host name. String
Examples
Usage example
icebergBucket
Introduced in: v25.5
Implements logic of iceberg bucket transform: https://iceberg.apache.org/spec/#bucket-transform-details.
Syntax
Arguments
N
— modulo, positive integer, always constant. -value
— Integer, bool, decimal, float, string, fixed_string, uuid, date, time or datetime value.
Returned value
Int32
Examples
Example
icebergHash
Introduced in: v25.5
Implements logic of iceberg hashing transform: https://iceberg.apache.org/spec/#appendix-b-32-bit-hash-requirements.
Syntax
Arguments
value
— Integer, bool, decimal, float, string, fixed_string, uuid, date, time, datetime.
Returned value
Int32
Examples
Example
icebergTruncate
Introduced in: v25.3
Implements logic of iceberg truncate transform: https://iceberg.apache.org/spec/#truncate-transform-details.
Syntax
Arguments
Returned value
The same type as the argument
Examples
Example
identity
Introduced in: v1.1
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
Arguments
x
— Input value.Any
Returned value
Returns the input value unchanged. Any
Examples
Usage example
ignore
Introduced in: v1.1
Accepts arbitrary arguments and unconditionally returns 0
.
Syntax
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
indexHint
Introduced in: v1.1
This function is intended for debugging and introspection. It ignores its argument and always returns 1. The arguments are not evaluated.
But during index analysis, the argument of this function is assumed to be not wrapped in indexHint
.
This allows 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.
Syntax
Arguments
expression
— Any expression for index range selection.Expression
Returned value
Returns 1
in all cases. UInt8
Examples
Usage example with date filtering
initialQueryID
Introduced in: v1.1
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
Arguments
- None. Returned value
Returns the ID of the initial current query. String
Examples
Usage example
initialQueryStartTime
Introduced in: v25.4
Returns the start time of the initial current query.
initialQueryStartTime
returns the same results on different shards.
Syntax
Arguments
- None. Returned value
Returns the start time of the initial current query. DateTime
Examples
Usage example
initializeAggregation
Introduced in: v20.6
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
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
Usage with sumState and finalizeAggregation
isConstant
Introduced in: v20.3
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
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
Constant with function
Non-constant expression
Behavior of the now() function
isDecimalOverflow
Introduced in: v20.8
Checks if a decimal number has too many digits to fit properly in a Decimal data type with given precision.
Syntax
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
joinGet
Introduced in: v18.16
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.
Only supports tables created with the ENGINE = Join(ANY, LEFT, <join_keys>)
statement.
Syntax
Arguments
join_storage_table_name
— An identifier which indicates where to perform the search. The identifier is searched in the default database (see parameterdefault_database
in the config file). To override the default database, use theUSE database_name
query or specify the database and the table through a dot, likedatabase_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
Usage with table from current database
Using arrays as join keys
joinGetOrNull
Introduced in: v20.4
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.
Only supports tables created with the ENGINE = Join(ANY, LEFT, <join_keys>)
statement.
Syntax
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 theUSE database_name
query or specify the database and the table through a dot, likedatabase_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
lowCardinalityIndices
Introduced in: v18.12
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
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
lowCardinalityKeys
Introduced in: v18.12
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
Arguments
col
— A low cardinality column.LowCardinality
Returned value
Returns the dictionary keys. UInt64
Examples
lowCardinalityKeys
materialize
Introduced in: v1.1
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
Arguments
x
— A constant.Any
Returned value
Returns a full column containing the constant value. Any
Examples
Usage example
minSampleSizeContinuous
Introduced in: v23.10
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
Arguments
baseline
— Baseline value of a metric.(U)Int*
orFloat*
sigma
— Baseline standard deviation of a metric.(U)Int*
orFloat*
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*
orFloat*
power
— Required statistical power of a test (1 - probability of Type II error).(U)Int*
orFloat*
alpha
— Required significance level of a test (probability of Type I error).(U)Int*
orFloat*
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
minSampleSizeConversion
Introduced in: v22.6
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
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
neighbor
Introduced in: v20.1
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
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
With default value
nested
Introduced in: v
This is a function used internally by the ClickHouse engine and not meant to be used directly.
Returns the array of tuples from multiple arrays.
The first argument must be a constant array of Strings determining the names of the resulting Tuple. The other arguments must be arrays of the same size.
Syntax
Arguments
- None. Returned value
Examples
nested
normalizeQuery
Introduced in: v20.8
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
Arguments
x
— Sequence of characters.String
Returned value
Returns the given sequence of characters with placeholders. String
Examples
Usage example
normalizeQueryKeepNames
Introduced in: v21.2
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
Arguments
x
— Sequence of characters.String
Returned value
Returns the given sequence of characters with placeholders. String
Examples
Usage example
normalizedQueryHash
Introduced in: v20.8
Returns identical 64 bit hash values without the values of literals for similar queries. Can be helpful in analyzing query logs.
Syntax
Arguments
x
— Sequence of characters.String
Returned value
Returns a 64 bit hash value. UInt64
Examples
Usage example
normalizedQueryHashKeepNames
Introduced in: v21.2
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
Arguments
x
— Sequence of characters.String
Returned value
Returns a 64 bit hash value. UInt64
Examples
Usage example
parseReadableSize
Introduced in: v24.6
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
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
parseReadableSizeOrNull
Introduced in: v24.6
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
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
parseReadableSizeOrZero
Introduced in: v24.6
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
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
parseTimeDelta
Introduced in: v22.7
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
Arguments
timestr
— A sequence of numbers followed by something resembling a time unit.String
Returned value
The number of seconds. Float64
Examples
Usage example
Complex time units
partitionId
Introduced in: v21.4
Computes the partition ID.
This function is slow and should not be called for large numbers of rows.
Syntax
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
queryID
Introduced in: v21.9
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
Arguments
- None. Returned value
Returns the ID of the current query. String
Examples
Usage example
revision
Introduced in: v22.7
Returns the current ClickHouse server revision.
Syntax
Arguments
- None. Returned value
Returns the current ClickHouse server revision. UInt32
Examples
Usage example
rowNumberInAllBlocks
Introduced in: v1.1
Returns a unique row number for each row processed.
Syntax
Arguments
- None. Returned value
Returns the ordinal number of the row in the data block starting from 0
. UInt64
Examples
Usage example
rowNumberInBlock
Introduced in: v1.1
For each block processed by rowNumberInBlock
, returns the number of the current row.
The returned number starts from 0 for each block.
Syntax
Arguments
- None. Returned value
Returns the ordinal number of the row in the data block starting from 0
. UInt64
Examples
Usage example
runningAccumulate
Introduced in: v1.1
Accumulates the states of an aggregate function for each row of a data block.
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 instead.
You can use setting allow_deprecated_error_prone_window_functions
to allow usage of this function.
Syntax
Arguments
agg_state
— State of the aggregate function.AggregateFunction
grouping
— Optional. Grouping key. The state of the function is reset if thegrouping
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
runningConcurrency
Introduced in: v21.3
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.
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.
It is advised to use window functions instead.
Syntax
Arguments
start
— A column with the start time of events.Date
orDateTime
orDateTime64
end
— A column with the end time of events.Date
orDateTime
orDateTime64
Returned value
Returns the number of concurrent events at each event start time. UInt32
Examples
Usage example
runningDifference
Introduced in: v1.1
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.
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.
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
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
Block size impact example
runningDifferenceStartingWithFirstValue
Introduced in: v1.1
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
.
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
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
serverUUID
Introduced in: v20.1
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
Arguments
- None. Returned value
Returns the random UUID of the server. UUID
Examples
Usage example
shardCount
Introduced in: v21.9
Returns the total number of shards for a distributed query.
If a query is not distributed then constant value 0
is returned.
Syntax
Arguments
- None. Returned value
Returns the total number of shards or 0
. UInt32
Examples
Usage example
shardNum
Introduced in: v21.9
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
Arguments
- None. Returned value
Returns the shard index or a constant 0
. UInt32
Examples
Usage example
showCertificate
Introduced in: v22.6
Shows information about the current server's Secure Sockets Layer (SSL) certificate if it has been configured. See Configuring SSL-TLS for more information on how to configure ClickHouse to use OpenSSL certificates to validate connections.
Syntax
Arguments
- None. Returned value
Returns map of key-value pairs relating to the configured SSL certificate. Map(String, String)
Examples
Usage example
sleep
Introduced in: v1.1
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.
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
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*
orconst Float*
Returned value
Returns 0
. UInt8
Examples
Usage example
sleepEachRow
Introduced in: v1.1
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.
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
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*
orconst Float*
Returned value
Returns 0
for each row. UInt8
Examples
Usage example
structureToCapnProtoSchema
Introduced in: v
Function that converts ClickHouse table structure to CapnProto format schema
Syntax
Arguments
- None. Returned value
Examples
random
structureToProtobufSchema
Introduced in: v
Function that converts ClickHouse table structure to Protobuf format schema
Syntax
Arguments
- None. Returned value
Examples
random
tcpPort
Introduced in: v20.12
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
Arguments
- None. Returned value
Returns the TCP port number. UInt16
Examples
Usage example
throwIf
Introduced in: v1.1
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
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
toColumnTypeName
Introduced in: v1.1
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
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
toTypeName
Introduced in: v1.1
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
Arguments
x
— A value of arbitrary type.Any
Returned value
Returns the data type name of the input value. String
Examples
Usage example
transactionID
Introduced in: v22.6
Returns the ID of a transaction.
This function is part of an experimental feature set. Enable experimental transaction support by adding this setting to your configuration:
For more information see the page Transactional (ACID) support.
Syntax
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
transactionLatestSnapshot
Introduced in: v22.6
Returns the newest snapshot (Commit Sequence Number) of a transaction that is available for reading.
This function is part of an experimental feature set. Enable experimental transaction support by adding this setting to your configuration:
For more information see the page Transactional (ACID) support.
Syntax
Arguments
- None. Returned value
Returns the latest snapshot (CSN) of a transaction. UInt64
Examples
Usage example
transactionOldestSnapshot
Introduced in: v22.6
Returns the oldest snapshot (Commit Sequence Number) that is visible for some running transaction.
This function is part of an experimental feature set. Enable experimental transaction support by adding this setting to your configuration:
For more information see the page Transactional (ACID) support.
Syntax
Arguments
- None. Returned value
Returns the oldest snapshot (CSN) of a transaction. UInt64
Examples
Usage example
transform
Introduced in: v1.1
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)
- transformsx
using mapping arrays with a default value for unmatched elementstransform(x, array_from, array_to)
- same transformation but returns the originalx
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
andarray_to
must have the same number of elements- For 4-parameter version:
transform(T, Array(T), Array(U), U) -> U
whereT
andU
can be different compatible types - For 3-parameter version:
transform(T, Array(T), Array(T)) -> T
where all types must be the same
Syntax
Arguments
x
— Value to transform.(U)Int*
orDecimal
orFloat*
orString
orDate
orDateTime
array_from
— Constant array of values to search for matches.Array((U)Int*)
orArray(Decimal)
orArray(Float*)
orArray(String)
orArray(Date)
orArray(DateTime)
array_to
— Constant array of values to return for corresponding matches inarray_from
.Array((U)Int*)
orArray(Decimal)
orArray(Float*)
orArray(String)
orArray(Date)
orArray(DateTime)
default
— Optional. Value to return ifx
is not found inarray_from
. If omitted, returns x unchanged.(U)Int*
orDecimal
orFloat*
orString
orDate
orDateTime
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
transform(T, Array(T), Array(T)) -> T
uniqThetaIntersect
Introduced in: v22.9
Two uniqThetaSketch objects to do intersect calculation(set operation ∩), the result is a new uniqThetaSketch.
Syntax
Arguments
uniqThetaSketch
— uniqThetaSketch object.Tuple
orArray
orDate
orDateTime
orString
or(U)Int*
orFloat*
orDecimal
Returned value
A new uniqThetaSketch containing the intersect result. UInt64
Examples
Usage example
uniqThetaNot
Introduced in: v22.9
Two uniqThetaSketch objects to do a_not_b calculation(set operation ×), the result is a new uniqThetaSketch.
Syntax
Arguments
uniqThetaSketch
— uniqThetaSketch object.Tuple
orArray
orDate
orDateTime
orString
or(U)Int*
orFloat*
orDecimal
Returned value
Returns a new uniqThetaSketch containing the a_not_b result. UInt64
Examples
Usage example
uniqThetaUnion
Introduced in: v22.9
Two uniqThetaSketch objects to do union calculation(set operation ∪), the result is a new uniqThetaSketch.
Syntax
Arguments
uniqThetaSketch
— uniqThetaSketch object.Tuple
orArray
orDate
orDateTime
orString
or(U)Int*
orFloat*
orDecimal
Returned value
Returns a new uniqThetaSketch containing the union result. UInt64
Examples
Usage example
uptime
Introduced in: v1.1
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
Arguments
- None. Returned value
Returns the server uptime in seconds. UInt32
Examples
Usage example
variantElement
Introduced in: v25.2
Extracts a column with specified type from a Variant
column.
Syntax
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
variantType
Introduced in: v24.2
Returns the variant type name for each row of Variant
column. If row contains NULL, it returns 'None' for it.
Syntax
Arguments
variant
— Variant column.Variant
Returned value
Returns an Enum column with variant type name for each row. Enum
Examples
Usage example
version
Introduced in: v1.1
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
Arguments
- None. Returned value
Returns the current version of ClickHouse. String
Examples
Usage example
visibleWidth
Introduced in: v1.1
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
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
zookeeperSessionUptime
Introduced in: v21.11
Returns the uptime of the current ZooKeeper session in seconds.
Syntax
Arguments
- None. Returned value
Returns the uptime of the current ZooKeeper session in seconds. UInt32
Examples
Usage example