Functions for Working with Dictionaries
For dictionaries created with DDL queries, the dict_name parameter must be fully specified, like <database>.<dict_name>. Otherwise, the current database is used.
For information on connecting and configuring dictionaries, see Dictionaries.
Example dictionaries
The examples in this section make use of the following dictionaries. You can create them in ClickHouse to run the examples for the functions described below.
Example dictionary for dictGet<T> and dictGet<T>OrDefault functions
Example dictionary for dictGetAll
Create a table to store the data for the regexp tree dictionary:
Insert data into the table:
Create the regexp tree dictionary:
Example range key dictionary
Create the input table:
Insert the data into the input table:
Create the dictionary:
Example complex key dictionary
Create the source table:
Insert the data into the source table:
Create the dictionary:
Example hierarchical dictionary
Create the source table:
Insert the data into the source table:
Create the dictionary:
dictGet
Introduced in: v18.16
Retrieves values from a dictionary.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_names— Name of the column of the dictionary, or tuple of column names.StringorTuple(String)id_expr— Key value. An expression returning UInt64/Tuple(T).UInt64orTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr if the key is found.
If the key is not found, returns the content of the <null_value> element specified for the attribute in the dictionary configuration.
Examples
Retrieve a single attribute
Multiple attributes
dictGetAll
Introduced in: v23.5
Converts a dictionary attribute value to All data type regardless of the dictionary configuration.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. An expression returning a dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the content of the <null_value> element specified for the attribute in the dictionary configuration.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetChildren
Introduced in: v21.4
Returns first-level children as an array of indexes. It is the inverse transformation for dictGetHierarchy.
Syntax
Arguments
dict_name— Name of the dictionary.Stringkey— Key to be checked.const String
Returned value
Returns the first-level descendants for the key. Array(UInt64)
Examples
Get the first-level children of a dictionary
dictGetDate
Introduced in: v1.1
Converts a dictionary attribute value to Date data type regardless of the dictionary configuration.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. An expression returning a dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the content of the <null_value> element specified for the attribute in the dictionary configuration.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetDateOrDefault
Introduced in: v1.1
Converts a dictionary attribute value to Date data type regardless of the dictionary configuration, or returns the provided default value if the key is not found.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. Expression returning dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)default_value_expr— Value(s) returned if the dictionary does not contain a row with theid_exprkey.ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the value passed as the default_value_expr parameter.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetDateTime
Introduced in: v1.1
Converts a dictionary attribute value to DateTime data type regardless of the dictionary configuration.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. An expression returning a dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the content of the <null_value> element specified for the attribute in the dictionary configuration.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetDateTimeOrDefault
Introduced in: v1.1
Converts a dictionary attribute value to DateTime data type regardless of the dictionary configuration, or returns the provided default value if the key is not found.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. Expression returning dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)default_value_expr— Value(s) returned if the dictionary does not contain a row with theid_exprkey.ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the value passed as the default_value_expr parameter.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetDescendants
Introduced in: v21.4
Returns all descendants as if the dictGetChildren function were applied level times recursively.
Syntax
Arguments
dict_name— Name of the dictionary.Stringkey— Key to be checked.const Stringlevel— Key to be checked. Hierarchy level. Iflevel = 0returns all descendants to the end.UInt8
Returned value
Returns the descendants for the key. Array(UInt64)
Examples
Get the first-level children of a dictionary
dictGetFloat32
Introduced in: v1.1
Converts a dictionary attribute value to Float32 data type regardless of the dictionary configuration.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. An expression returning a dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the content of the <null_value> element specified for the attribute in the dictionary configuration.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetFloat32OrDefault
Introduced in: v1.1
Converts a dictionary attribute value to Float32 data type regardless of the dictionary configuration, or returns the provided default value if the key is not found.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. Expression returning dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)default_value_expr— Value(s) returned if the dictionary does not contain a row with theid_exprkey.ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the value passed as the default_value_expr parameter.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetFloat64
Introduced in: v1.1
Converts a dictionary attribute value to Float64 data type regardless of the dictionary configuration.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. An expression returning a dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the content of the <null_value> element specified for the attribute in the dictionary configuration.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetFloat64OrDefault
Introduced in: v1.1
Converts a dictionary attribute value to Float64 data type regardless of the dictionary configuration, or returns the provided default value if the key is not found.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. Expression returning dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)default_value_expr— Value(s) returned if the dictionary does not contain a row with theid_exprkey.ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the value passed as the default_value_expr parameter.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetHierarchy
Introduced in: v1.1
Creates an array, containing all the parents of a key in the hierarchical dictionary.
Syntax
Arguments
dict_name— Name of the dictionary.Stringkey— Key value.const String
Returned value
Returns parents for the key. Array(UInt64)
Examples
Get hierarchy for a key
dictGetIPv4
Introduced in: v1.1
Converts a dictionary attribute value to IPv4 data type regardless of the dictionary configuration.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. An expression returning a dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the content of the <null_value> element specified for the attribute in the dictionary configuration.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetIPv4OrDefault
Introduced in: v23.1
Converts a dictionary attribute value to IPv4 data type regardless of the dictionary configuration, or returns the provided default value if the key is not found.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. Expression returning dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)default_value_expr— Value(s) returned if the dictionary does not contain a row with theid_exprkey.ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the value passed as the default_value_expr parameter.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetIPv6
Introduced in: v23.1
Converts a dictionary attribute value to IPv6 data type regardless of the dictionary configuration.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. An expression returning a dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the content of the <null_value> element specified for the attribute in the dictionary configuration.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetIPv6OrDefault
Introduced in: v23.1
Converts a dictionary attribute value to IPv6 data type regardless of the dictionary configuration, or returns the provided default value if the key is not found.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. Expression returning dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)default_value_expr— Value(s) returned if the dictionary does not contain a row with theid_exprkey.ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the value passed as the default_value_expr parameter.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetInt16
Introduced in: v1.1
Converts a dictionary attribute value to Int16 data type regardless of the dictionary configuration.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. An expression returning a dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the content of the <null_value> element specified for the attribute in the dictionary configuration.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetInt16OrDefault
Introduced in: v1.1
Converts a dictionary attribute value to Int16 data type regardless of the dictionary configuration, or returns the provided default value if the key is not found.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. Expression returning dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)default_value_expr— Value(s) returned if the dictionary does not contain a row with theid_exprkey.ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the value passed as the default_value_expr parameter.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetInt32
Introduced in: v1.1
Converts a dictionary attribute value to Int32 data type regardless of the dictionary configuration.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. An expression returning a dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the content of the <null_value> element specified for the attribute in the dictionary configuration.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetInt32OrDefault
Introduced in: v1.1
Converts a dictionary attribute value to Int32 data type regardless of the dictionary configuration, or returns the provided default value if the key is not found.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. Expression returning dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)default_value_expr— Value(s) returned if the dictionary does not contain a row with theid_exprkey.ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the value passed as the default_value_expr parameter.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetInt64
Introduced in: v1.1
Converts a dictionary attribute value to Int64 data type regardless of the dictionary configuration.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. An expression returning a dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the content of the <null_value> element specified for the attribute in the dictionary configuration.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetInt64OrDefault
Introduced in: v1.1
Converts a dictionary attribute value to Int64 data type regardless of the dictionary configuration, or returns the provided default value if the key is not found.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. Expression returning dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)default_value_expr— Value(s) returned if the dictionary does not contain a row with theid_exprkey.ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the value passed as the default_value_expr parameter.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetInt8
Introduced in: v1.1
Converts a dictionary attribute value to Int8 data type regardless of the dictionary configuration.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. An expression returning a dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the content of the <null_value> element specified for the attribute in the dictionary configuration.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetInt8OrDefault
Introduced in: v1.1
Converts a dictionary attribute value to Int8 data type regardless of the dictionary configuration, or returns the provided default value if the key is not found.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. Expression returning dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)default_value_expr— Value(s) returned if the dictionary does not contain a row with theid_exprkey.ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the value passed as the default_value_expr parameter.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetKeys
Introduced in: v25.12
Returns the dictionary key(s) whose attribute equals the specified value. This is the inverse of the function dictGet on a single attribute.
Use setting max_reverse_dictionary_lookup_cache_size_bytes to cap the size of the per-query reverse-lookup cache used by dictGetKeys.
The cache stores serialized key tuples for each attribute value to avoid re-scanning the dictionary within the same query.
The cache is not persistent across queries. When the limit is reached, entries are evicted with LRU.
This is most effective with large dictionaries when the input has low cardinality and the working set fits in the cache. Set to 0 to disable caching.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Attribute to match.Stringvalue_expr— Value to match against the attribute.Expression
Returned value
For single key dictionaries: an array of keys whose attribute equals value_expr. For multi key dictionaries: an array of tuples of keys whose attribute equals value_expr. If there is no attribute corresponding to value_expr in the dictionary, then an empty array is returned. ClickHouse throws an exception if it cannot parse the value of the attribute or the value cannot be converted to the attribute data type.
Examples
Sample usage
dictGetOrDefault
Introduced in: v18.16
Retrieves values from a dictionary, with a default value if the key is not found.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_names— Name of the column of the dictionary, or tuple of column names.StringorTuple(String)id_expr— Key value. An expression returning UInt64/Tuple(T).UInt64orTuple(T)default_value— Default value to return if the key is not found. Type must match the attribute's data type.
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr if the key is found.
If the key is not found, returns the default_value provided.
Examples
Get value with default
dictGetOrNull
Introduced in: v21.4
Retrieves values from a dictionary, returning NULL if the key is not found.
Syntax
Arguments
dict_name— Name of the dictionary. String literal. -attr_name— Name of the column to retrieve. String literal. -id_expr— Key value. Expression returning dictionary key-type value.
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr if the key is found.
If the key is not found, returns NULL.
Examples
Example using the range key dictionary
dictGetString
Introduced in: v1.1
Converts a dictionary attribute value to String data type regardless of the dictionary configuration.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. An expression returning a dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the content of the <null_value> element specified for the attribute in the dictionary configuration.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetStringOrDefault
Introduced in: v1.1
Converts a dictionary attribute value to String data type regardless of the dictionary configuration, or returns the provided default value if the key is not found.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. Expression returning dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)default_value_expr— Value(s) returned if the dictionary does not contain a row with theid_exprkey.ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the value passed as the default_value_expr parameter.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetUInt16
Introduced in: v1.1
Converts a dictionary attribute value to UInt16 data type regardless of the dictionary configuration.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. An expression returning a dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the content of the <null_value> element specified for the attribute in the dictionary configuration.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetUInt16OrDefault
Introduced in: v1.1
Converts a dictionary attribute value to UInt16 data type regardless of the dictionary configuration, or returns the provided default value if the key is not found.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. Expression returning dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)default_value_expr— Value(s) returned if the dictionary does not contain a row with theid_exprkey.ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the value passed as the default_value_expr parameter.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetUInt32
Introduced in: v1.1
Converts a dictionary attribute value to UInt32 data type regardless of the dictionary configuration.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. An expression returning a dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the content of the <null_value> element specified for the attribute in the dictionary configuration.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetUInt32OrDefault
Introduced in: v1.1
Converts a dictionary attribute value to UInt32 data type regardless of the dictionary configuration, or returns the provided default value if the key is not found.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. Expression returning dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)default_value_expr— Value(s) returned if the dictionary does not contain a row with theid_exprkey.ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the value passed as the default_value_expr parameter.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetUInt64
Introduced in: v1.1
Converts a dictionary attribute value to UInt64 data type regardless of the dictionary configuration.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. An expression returning a dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the content of the <null_value> element specified for the attribute in the dictionary configuration.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetUInt64OrDefault
Introduced in: v1.1
Converts a dictionary attribute value to UInt64 data type regardless of the dictionary configuration, or returns the provided default value if the key is not found.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. Expression returning dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)default_value_expr— Value(s) returned if the dictionary does not contain a row with theid_exprkey.ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the value passed as the default_value_expr parameter.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetUInt8
Introduced in: v1.1
Converts a dictionary attribute value to UInt8 data type regardless of the dictionary configuration.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. An expression returning a dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the content of the <null_value> element specified for the attribute in the dictionary configuration.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetUInt8OrDefault
Introduced in: v1.1
Converts a dictionary attribute value to UInt8 data type regardless of the dictionary configuration, or returns the provided default value if the key is not found.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. Expression returning dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)default_value_expr— Value(s) returned if the dictionary does not contain a row with theid_exprkey.ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the value passed as the default_value_expr parameter.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetUUID
Introduced in: v1.1
Converts a dictionary attribute value to UUID data type regardless of the dictionary configuration.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. An expression returning a dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the content of the <null_value> element specified for the attribute in the dictionary configuration.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictGetUUIDOrDefault
Introduced in: v1.1
Converts a dictionary attribute value to UUID data type regardless of the dictionary configuration, or returns the provided default value if the key is not found.
Syntax
Arguments
dict_name— Name of the dictionary.Stringattr_name— Name of the column of the dictionary.StringorTuple(String)id_expr— Key value. Expression returning dictionary key-type value or tuple value (dictionary configuration dependent).ExpressionorTuple(T)default_value_expr— Value(s) returned if the dictionary does not contain a row with theid_exprkey.ExpressionorTuple(T)
Returned value
Returns the value of the dictionary attribute that corresponds to id_expr,
otherwise returns the value passed as the default_value_expr parameter.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Examples
Usage example
dictHas
Introduced in: v1.1
Checks whether a key is present in a dictionary.
Syntax
Arguments
dict_name— Name of the dictionary.Stringid_expr— Key valueconst String
Returned value
Returns 1 if the key exists, otherwise 0. UInt8
Examples
Check for the existence of a key in a dictionary
dictIsIn
Introduced in: v1.1
Checks the ancestor of a key through the whole hierarchical chain in the dictionary.
Syntax
Arguments
dict_name— Name of the dictionary.Stringchild_id_expr— Key to be checked.Stringancestor_id_expr— Alleged ancestor of thechild_id_exprkey.const String
Returned value
Returns 0 if child_id_expr is not a child of ancestor_id_expr, 1 if child_id_expr is a child of ancestor_id_expr or if child_id_expr is an ancestor_id_expr. UInt8
Examples
Check hierarchical relationship