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.
dictGet, dictGetOrDefault, dictGetOrNull
Retrieves values from a dictionary.
Arguments
dict_name— Name of the dictionary. String literal.attr_names— Name of the column of the dictionary, String literal, or tuple of column names, Tuple(String literal.id_expr— Key value. Expression returning dictionary key-type value or Tuple-type value depending on the dictionary configuration.default_value_expr— Values returned if the dictionary does not contain a row with theid_exprkey. Expression or Tuple(Expression), returning the value (or values) in the data types configured for theattr_namesattribute.
Returned value
-
If ClickHouse parses the attribute successfully in the attribute's data type, functions return the value of the dictionary attribute that corresponds to
id_expr. -
If there is no the key, corresponding to
id_expr, in the dictionary, then:dictGetreturns the content of the<null_value>element specified for the attribute in the dictionary configuration.dictGetOrDefaultreturns the value passed as thedefault_value_exprparameter.dictGetOrNullreturnsNULLin case key was not found in dictionary.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Example for simple key dictionary
Create a text file ext-dict-test.csv containing the following:
The first column is id, the second column is c1.
Configure the dictionary:
Perform the query:
Example for complex key dictionary
Create a text file ext-dict-mult.csv containing the following:
The first column is id, the second is c1, the third is c2.
Configure the dictionary:
Perform the query:
Example for range key dictionary
Input table:
Create the dictionary:
Perform the query:
Result:
See Also
dictHas
Checks whether a key is present in a dictionary.
Arguments
dict_name— Name of the dictionary. String literal.id_expr— Key value. Expression returning dictionary key-type value or Tuple-type value depending on the dictionary configuration.
Returned value
dictGetHierarchy
Creates an array, containing all the parents of a key in the hierarchical dictionary.
Syntax
Arguments
dict_name— Name of the dictionary. String literal.key— Key value. Expression returning a UInt64-type value.
Returned value
- Parents for the key. Array(UInt64).
dictIsIn
Checks the ancestor of a key through the whole hierarchical chain in the dictionary.
Arguments
dict_name— Name of the dictionary. String literal.child_id_expr— Key to be checked. Expression returning a UInt64-type value.ancestor_id_expr— Alleged ancestor of thechild_id_exprkey. Expression returning a UInt64-type value.
Returned value
- 0, if
child_id_expris not a child ofancestor_id_expr. UInt8. - 1, if
child_id_expris a child ofancestor_id_expror ifchild_id_expris anancestor_id_expr. UInt8.
dictGetChildren
Returns first-level children as an array of indexes. It is the inverse transformation for dictGetHierarchy.
Syntax
Arguments
dict_name— Name of the dictionary. String literal.key— Key value. Expression returning a UInt64-type value.
Returned values
Example
Consider the hierarchic dictionary:
First-level children:
dictGetDescendant
Returns all descendants as if dictGetChildren function was applied level times recursively.
Syntax
Arguments
dict_name— Name of the dictionary. String literal.key— Key value. Expression returning a UInt64-type value.level— Hierarchy level. Iflevel = 0returns all descendants to the end. UInt8.
Returned values
Example
Consider the hierarchic dictionary:
All descendants:
First-level descendants:
dictGetAll
Retrieves the attribute values of all nodes that matched each key in a regular expression tree dictionary.
Besides returning values of type Array(T) instead of T, this function behaves similarly to dictGet.
Syntax
Arguments
dict_name— Name of the dictionary. String literal.attr_names— Name of the column of the dictionary, String literal, or tuple of column names, Tuple(String literal).id_expr— Key value. Expression returning array of dictionary key-type value or Tuple-type value depending on the dictionary configuration.limit- Maximum length for each value array returned. When truncating, child nodes are given precedence over parent nodes, and otherwise the defined list order for the regexp tree dictionary is respected. If unspecified, array length is unlimited.
Returned value
-
If ClickHouse parses the attribute successfully in the attribute's data type as defined in the dictionary, returns an array of dictionary attribute values that correspond to
id_exprfor each attribute specified byattr_names. -
If there is no key corresponding to
id_exprin the dictionary, then an empty array is returned.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Example
Consider the following regexp tree dictionary:
Get all matching values:
Get up to 2 matching values:
Other Functions
ClickHouse supports specialized functions that convert dictionary attribute values to a specific data type regardless of the dictionary configuration.
Functions:
dictGetInt8,dictGetInt16,dictGetInt32,dictGetInt64dictGetUInt8,dictGetUInt16,dictGetUInt32,dictGetUInt64dictGetFloat32,dictGetFloat64dictGetDatedictGetDateTimedictGetUUIDdictGetStringdictGetIPv4,dictGetIPv6
All these functions have the OrDefault modification. For example, dictGetDateOrDefault.
Syntax:
Arguments
dict_name— Name of the dictionary. String literal.attr_name— Name of the column of the dictionary. String literal.id_expr— Key value. Expression returning a UInt64 or Tuple-type value depending on the dictionary configuration.default_value_expr— Value returned if the dictionary does not contain a row with theid_exprkey. Expression returning the value in the data type configured for theattr_nameattribute.
Returned value
-
If ClickHouse parses the attribute successfully in the attribute's data type, functions return the value of the dictionary attribute that corresponds to
id_expr. -
If there is no requested
id_exprin the dictionary then:dictGet[Type]returns the content of the<null_value>element specified for the attribute in the dictionary configuration.dictGet[Type]OrDefaultreturns the value passed as thedefault_value_exprparameter.
ClickHouse throws an exception if it cannot parse the value of the attribute or the value does not match the attribute data type.
Example dictionaries
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
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