Skip to main content
All functions in this section search case-sensitively by default. Case-insensitive search is usually provided by separate function variants.
Case-insensitive search follows the lowercase-uppercase rules of the English language. E.g. Uppercased i in the English language is I whereas in the Turkish language it is İ - results for languages other than English may be unexpected.
Functions in this section also assume that the searched string (referred to in this section as haystack) and the search string (referred to in this section as needle) are single-byte encoded text. If this assumption is violated, no exception is thrown and results are undefined. Search with UTF-8 encoded strings is usually provided by separate function variants. Likewise, if a UTF-8 function variant is used and the input strings are not UTF-8 encoded text, no exception is thrown and the results are undefined. Note that no automatic Unicode normalization is performed, however you can use the normalizeUTF8*() functions for that. General strings functions and functions for replacing in strings are described separately.
The documentation below is generated from the system.functions system table.

countMatches

Introduced in: v21.1.0 Returns number of matches of a regular expression in a string.
Version dependent behaviorThe behavior of this function depends on the ClickHouse version:
  • in versions < v25.6, the function stops counting at the first empty match even if a pattern accepts.
  • in versions >= 25.6, the function continues execution when an empty match occurs. The legacy behavior can be restored using setting count_matches_stop_at_empty_match = true;
Syntax
Arguments
  • haystack — The string to search in. String
  • pattern — Regular expression pattern. String
Returned value Returns the number of matches found. UInt64 Examples Count digit sequences
Query
Response

countMatchesCaseInsensitive

Introduced in: v21.1.0 Like countMatches but performs case-insensitive matching. Syntax
Arguments
  • haystack — The string to search in. String
  • pattern — Regular expression pattern. const String
Returned value Returns the number of matches found. UInt64 Examples Case insensitive count
Query
Response

countSubstrings

Introduced in: v21.1.0 Returns how often a substring needle occurs in a string haystack. Syntax
Arguments
  • haystack — String in which the search is performed. String or Enum. - needle — Substring to be searched. String. - start_pos — Position (1-based) in haystack at which the search starts. UInt. Optional.
Returned value The number of occurrences. UInt64 Examples Usage example
Query
Response
With start_pos argument
Query
Response

countSubstringsCaseInsensitive

Introduced in: v21.1.0 Like countSubstrings but counts case-insensitively. Syntax
Arguments
  • haystack — String in which the search is performed. String or Enum
  • needle — Substring to be searched. String
  • start_pos — Optional. Position (1-based) in haystack at which the search starts. UInt*
Returned value Returns the number of occurrences of the neddle in the haystack. UInt64 Examples Usage example
Query
Response
With start_pos argument
Query
Response

countSubstringsCaseInsensitiveUTF8

Introduced in: v21.1.0 Like countSubstrings but counts case-insensitively and assumes that haystack is a UTF-8 string. Syntax
Arguments
  • haystack — UTF-8 string in which the search is performed. String or Enum
  • needle — Substring to be searched. String
  • start_pos — Optional. Position (1-based) in haystack at which the search starts. UInt*
Returned value Returns the number of occurrences of the needle in the haystack. UInt64 Examples Usage example
Query
Response
With start_pos argument
Query
Response

extract

Introduced in: v1.1.0 Extracts the first match of a regular expression in a string. If ‘haystack’ doesn’t match ‘pattern’, an empty string is returned. This function uses the RE2 regular expression library. Please refer to re2 for supported syntax. If the regular expression has capturing groups (sub-patterns), the function matches the input string against the first capturing group. Syntax
Arguments
  • haystack — String from which to extract. String
  • pattern — Regular expression, typically containing a capturing group. const String
Returned value Returns extracted fragment as a string. String Examples Extract domain from email
Query
Response
No match returns empty string
Query
Response

extractAll

Introduced in: v1.1.0 Like extract, but returns an array of all matches of a regular expression in a string. If ‘haystack’ doesn’t match the ‘pattern’ regex, an empty array is returned. If the regular expression has capturing groups (sub-patterns), the function matches the input string against the first capturing group. Syntax
Arguments
  • haystack — String from which to extract fragments. String
  • pattern — Regular expression, optionally containing capturing groups. const String
Returned value Returns array of extracted fragments. Array(String) Examples Extract all numbers
Query
Response
Extract using capturing group
Query
Response

extractAllGroupsHorizontal

Introduced in: v20.5.0 Matches all groups of a string using the provided regular expression and returns an array of arrays, where each array contains all captures from the same capturing group, organized by group number. Syntax
Arguments Returned value Returns an array of arrays, where each inner array contains all captures from one capturing group across all matches. The first inner array contains all captures from group 1, the second from group 2, etc. If no matches are found, returns an empty array. Array(Array(String)) Examples Usage example
Query
Response

extractGroups

Introduced in: v20.5.0 Extracts the capturing groups from the first substring matched by a regular expression. To extract groups from all matches, use extractAllGroupsHorizontal or extractAllGroupsVertical. Syntax
Arguments Returned value If the regular expression matches, returns an array containing the captured groups (1 to N, where N is the number of capturing groups in regexp) of the first match. If there is no match, returns an empty array. Array(String) Examples Usage example
Query
Response

hasAllTokens

Introduced in: v25.10.0 Like hasAnyTokens, but returns 1, if all tokens in the needle string or array match the input string, and 0 otherwise. If input is a column, returns all rows that satisfy this condition.
Column input should have a text index defined for optimal performance. If no text index is defined, the function performs a brute-force column scan which is orders of magnitude slower than an index lookup.
Prior to searching, the function tokenizes
  • the input argument (always), and
  • the needle argument (if given as a String) using the tokenizer specified for the text index. If the column has no text index defined, the splitByNonAlpha tokenizer is used instead. If the needle argument is of type Array(String), each array element is treated as a token — no additional tokenization takes place. If the text index has a preprocessor expression configured, the preprocessor is applied to the needle (if given as a String) before tokenization. If the text index has a postprocessor expression configured, the postprocessor is applied to needle tokens and the input tokens (i.e. both after tokenization).
Duplicate tokens are ignored. For example, needles = [‘ClickHouse’, ‘ClickHouse’] is treated the same as [‘ClickHouse’].
When a text index defines a preprocessor (for example lowerUTF8), hasAllTokens applies it to input and, when needles is a String, to needles before tokenization. When needles is an Array(String), its elements are passed through as-is and the preprocessor is not applied to them. The preprocessor is only applied on the text index path, so results may differ between queries that use the text index and queries that do not (e.g. SETTINGS use_skip_indexes = 0). This inconsistency is tolerated to improve the usability of full-text search.
Syntax
Aliases: hasAllToken Arguments Returned value Returns 1, if all needles match. 0, otherwise. UInt8 Examples Basic usage with a string needle
Query
Response
Specify needles to be searched for AS-IS (no tokenization) in an array
Query
Response
Generate needles using the tokens function
Query
Response
Use a custom tokenizer via the 3rd argument
Query
Response
Usage examples for array and map columns
Query
Response
Example with an array column
Query
Response
Example with mapKeys
Query
Response
Example with mapValues
Query
Response

hasAnyTokens

Introduced in: v25.10.0 Returns 1, if at least one token in the needle string or array matches the input string, and 0 otherwise. If input is a column, returns all rows that satisfy this condition.
Column input should have a text index defined for optimal performance. If no text index is defined, the function performs a brute-force column scan which is orders of magnitude slower than an index lookup.
Prior to searching, the function tokenizes
  • the input argument (always), and
  • the needle argument (if given as a String) using the tokenizer specified for the text index. If the column has no text index defined, the splitByNonAlpha tokenizer is used instead. If the needle argument is of type Array(String), each array element is treated as a token — no additional tokenization takes place. If the text index has a preprocessor expression configured, the preprocessor is applied to the needle (if given as a String) before tokenization. If the text index has a postprocessor expression configured, the postprocessor is applied to needle tokens and the input tokens (i.e. both after tokenization).
Duplicate tokens are ignored. For example, [‘ClickHouse’, ‘ClickHouse’] is treated the same as [‘ClickHouse’].
When a text index defines a preprocessor (for example lowerUTF8), hasAnyTokens applies it to input and, when needles is a String, to needles before tokenization. When needles is an Array(String), its elements are passed through as-is and the preprocessor is not applied to them. The preprocessor is only applied on the text index path, so results may differ between queries that use the text index and queries that do not (e.g. SETTINGS use_skip_indexes = 0). This inconsistency is tolerated to improve the usability of full-text search.
Syntax
Aliases: hasAnyToken Arguments Returned value Returns 1, if there was at least one match. 0, otherwise. UInt8 Examples Basic usage with a string needle
Query
Response
Specify needles to be searched for AS-IS (no tokenization) in an array
Query
Response
Generate needles using the tokens function
Query
Response
Usage examples for array and map columns
Query
Response
Example with an array column
Query
Response
Example with mapKeys
Query
Response
Example with mapValues
Query
Response

hasPhrase

Introduced in: v26.4.0 Checks if the input contains all tokens from the phrase in consecutive order.
Column input should have a text index defined for optimal performance. If no text index is defined, the function performs a brute-force column scan which is orders of magnitude slower than an index lookup.
Prior to searching, the function tokenizes both the input and the phrase arguments using the tokenizer specified for the text index. If the column has no text index defined, the splitByNonAlpha tokenizer is used instead — unless a tokenizer is provided as the optional third argument. The tokenizer argument must be one of splitByNonAlpha, splitByString, ngrams, or asciiCJK.
When a text index defines a preprocessor (for example lowerUTF8), hasPhrase applies it to both input and phrase before tokenization. The preprocessor is only applied on the text index path, so results may differ between queries that use the text index and queries that do not (e.g. SETTINGS use_skip_indexes = 0). This inconsistency is tolerated to improve the usability of full-text search.
Unlike hasToken, hasAnyTokens and hasAllTokens, hasPhrase requires the tokens to appear in the same order and without any intervening tokens. For example, hasPhrase('the quick brown fox', 'quick fox') returns 0 because “brown” appears between “quick” and “fox”. Syntax
Aliases: matchPhrase Arguments Returned value Returns 1 if the phrase is found as a consecutive token sequence, 0 otherwise. UInt8 Examples Phrase match
Query
Response
Non-consecutive tokens
Query
Response

hasSubsequence

Introduced in: v23.7.0 Checks if a needle is a subsequence of a haystack. A subsequence of a string is a sequence that can be derived from another string by deleting some or no characters without changing the order of the remaining characters. Syntax
Arguments
  • haystack — String in which to search for the subsequence. String
  • needle — Subsequence to be searched. String
Returned value Returns 1 if needle is a subsequence of haystack, 0 otherwise. UInt8 Examples Basic subsequence check
Query
Response
No subsequence found
Query
Response

hasSubsequenceCaseInsensitive

Introduced in: v23.7.0 Like hasSubsequence but searches case-insensitively. Syntax
Arguments
  • haystack — String in which the search is performed. String
  • needle — Subsequence to be searched. String
Returned value Returns 1, if needle is a subsequence of haystack, 0 otherwise. UInt8 Examples Usage example
Query
Response

hasSubsequenceCaseInsensitiveUTF8

Introduced in: v23.7.0 Like hasSubsequenceUTF8 but searches case-insensitively. Syntax
Arguments
  • haystack — UTF8-encoded string in which the search is performed. String
  • needle — UTF8-encoded subsequence string to be searched. String
Returned value Returns 1, if needle is a subsequence of haystack, 0 otherwise. UInt8 Examples Usage example
Query
Response

hasSubsequenceUTF8

Introduced in: v23.7.0 Like hasSubsequence but assumes haystack and needle are UTF-8 encoded strings. Syntax
Arguments
  • haystack — The string in which to search. String
  • needle — The subsequence to search for. String
Returned value Returns 1 if needle is a subsequence of haystack, otherwise 0. UInt8 Examples Usage example
Query
Response
Non-matching subsequence
Query
Response

hasToken

Introduced in: v20.1.0 Checks if the given token is present in the haystack. Uses splitByNonAlpha as tokenizer, i.e. a token is defined as the longest possible sub-sequence of consecutive characters [0-9A-Za-z_] (numbers, ASCII characters and underscore). Syntax
Arguments Returned value Returns 1 if the token is found, 0 otherwise. UInt8 Examples Token search
Query
Response

hasTokenCaseInsensitive

Introduced in: v20.1.0 Performs case insensitive lookup of needle in haystack using tokenbf_v1 index.
This function has certain pitfalls with non-default tokenizers and preprocessor or postprocessor expressions. We recommend using hasAnyTokens and hasAllTokens instead.
Syntax
Arguments
  • None.
Returned value Examples

hasTokenCaseInsensitiveOrNull

Introduced in: v23.1.0 Performs case insensitive lookup of needle in haystack using tokenbf_v1 index. Returns null if needle is ill-formed.
This function has certain pitfalls with non-default tokenizers and preprocessor or postprocessor expressions. We recommend using hasAnyTokens and hasAllTokens instead.
Syntax
Arguments
  • None.
Returned value Examples

hasTokenOrNull

Introduced in: v20.1.0 Like hasToken but returns null if token is ill-formed. Syntax
Arguments
  • haystack — String to be searched. Must be constant. String
  • token — Token to search for. const String
Returned value Returns 1 if the token is found, 0 otherwise, null if token is ill-formed. Nullable(UInt8) Examples Usage example
Query
Response

highlight

Introduced in: v26.4.0 Highlights occurrences of search terms in a text string by wrapping them with HTML tags. The function performs ASCII case-insensitive matching. If multiple search terms overlap or are adjacent in the text, the matched regions are merged into a single highlighted span. Syntax
Arguments
  • haystack — The text to search in. String or FixedString
  • needles — An array of search terms to highlight. const Array(String)
  • open_tag — The opening tag to insert before each match. Default: <em>. const String
  • close_tag — The closing tag to insert after each match. Default: </em>. const String
Returned value Returns the input text with matched terms wrapped in the specified tags. String Examples Basic highlight
Query
Response
Custom tags
Query
Response

ilike

Introduced in: v20.6.0 Like like but searches case-insensitively. Supports the optional ESCAPE clause (see like). Syntax
Arguments
  • haystack — String in which the search is performed. String or FixedString
  • pattern — LIKE pattern to match against. String
  • escape_character — Optional single-character string to use as the escape character instead of \. Default: \. String
Returned value Returns 1 if the string matches the LIKE pattern (case-insensitive), otherwise 0. UInt8 Examples Usage example
Query
Response

like

Introduced in: v1.1.0 Returns whether string haystack matches the LIKE expression pattern. A LIKE expression can contain normal characters and the following metasymbols:
  • % indicates an arbitrary number of arbitrary characters (including zero characters).
  • _ indicates a single arbitrary character.
  • \ is for escaping literals %, _ and \.
Matching is based on UTF-8, e.g. _ matches the Unicode code point ¥ which is represented in UTF-8 using two bytes. If the haystack or the LIKE expression are not valid UTF-8, the behavior is undefined. No automatic Unicode normalization is performed, you can use the normalizeUTF8* functions for that. To match against literal %, _ and \ (which are LIKE metacharacters), prepend them with a backslash: \%, \_ and \\. The backslash loses its special meaning (i.e. is interpreted literally) if it prepends a character different than %, _ or \.
ClickHouse requires backslashes in strings to be quoted as well, so you would actually need to write \\%, \\_ and \\\\.
For LIKE expressions of the form %needle%, the function is as fast as the position function. All other LIKE expressions are internally converted to a regular expression and executed with a performance similar to function match.

ESCAPE clause

The optional ESCAPE clause specifies a custom escape character (must be a single ASCII character). When provided, the custom escape character replaces the default backslash for escaping % and _ metacharacters. The escape character can escape three things: % (literal percent), _ (literal underscore), and itself (literal escape character). When a custom escape character is used, the backslash has no special meaning and is treated as a literal character. Syntax
Arguments
  • haystack — String in which the search is performed. String or FixedString
  • patternLIKE pattern to match against. Can contain % (matches any number of characters), _ (matches single character), and \ for escaping. String
  • escape_character — Optional single-character string to use as the escape character instead of \. Default: \. String
Returned value Returns 1 if the string matches the LIKE pattern, otherwise 0. UInt8 Examples Usage example
Query
Response
Single character wildcard
Query
Response
Non-matching pattern
Query
Response
ESCAPE clause
Query
Response

locate

Introduced in: v18.16.0 Like position but with arguments haystack and locate switched.
Version dependent behaviorThe behavior of this function depends on the ClickHouse version:
  • in versions < v24.3, locate was an alias of function position and accepted arguments (haystack, needle[, start_pos]).
  • in versions >= 24.3, locate is an individual function (for better compatibility with MySQL) and accepts arguments (needle, haystack[, start_pos]). The previous behavior can be restored using setting function_locate_has_mysql_compatible_argument_order = false.
Syntax
Arguments
  • needle — Substring to be searched. String
  • haystack — String in which the search is performed. String or Enum
  • start_pos — Optional. Position (1-based) in haystack at which the search starts. UInt
Returned value Returns starting position in bytes and counting from 1, if the substring was found, 0, if the substring was not found. UInt64 Examples Basic usage
Query
Response

match

Introduced in: v1.1.0 Checks if a provided string matches the provided regular expression pattern. This function uses the RE2 regular expression library. Please refer to re2 for supported syntax. Matching works under UTF-8 assumptions, e.g. ¥ uses two bytes internally but matching treats it as a single codepoint. The regular expression must not contain NULL bytes. If the haystack or the pattern are not valid UTF-8, the behavior is undefined. Unlike re2’s default behavior, . matches line breaks. To disable this, prepend the pattern with (?-s). The pattern is not anchored. To match the entire string, anchor the pattern yourself using ^ and $. If you just want to search for substrings, you can use functions like or position instead, which work much faster than this function. Alternative operator syntax: haystack REGEXP pattern. Syntax
Aliases: REGEXP_MATCHES Arguments
  • haystack — String in which the pattern is searched. String
  • pattern — Regular expression pattern. Can be a constant or come from a column. String
Returned value Returns 1 if the pattern matches, 0 otherwise. UInt8 Examples Basic pattern matching
Query
Response
Pattern not matching
Query
Response
Matching a substring
Query
Response

multiFuzzyMatchAllIndices

Introduced in: v20.1.0 Like multiFuzzyMatchAny but returns the array of all indices in any order that match the haystack within a constant edit distance. Syntax
Arguments
  • haystack — String in which the search is performed. String
  • distance — The maximum edit distance for fuzzy matching. UInt8
  • pattern — Array of patterns to match against. Array(String)
Returned value Returns an array of all indices (starting from 1) that match the haystack within the specified edit distance in any order. Returns an empty array if no matches are found. Array(UInt64) Examples Usage example
Query
Response

multiFuzzyMatchAny

Introduced in: v20.1.0 Like multiMatchAny but returns 1 if any pattern matches the haystack within a constant edit distance. This function relies on the experimental feature of hyperscan library, and can be slow for some edge cases. The performance depends on the edit distance value and patterns used, but it’s always more expensive compared to non-fuzzy variants.
multiFuzzyMatch*() function family do not support UTF-8 regular expressions (it treats them as a sequence of bytes) due to restrictions of hyperscan.
Syntax
Arguments
  • haystack — String in which the search is performed. String
  • distance — The maximum edit distance for fuzzy matching. UInt8
  • pattern — Optional. An array of patterns to match against. Array(String)
Returned value Returns 1 if any pattern matches the haystack within the specified edit distance, otherwise 0. UInt8 Examples Usage example
Query
Response

multiFuzzyMatchAnyIndex

Introduced in: v20.1.0 Like multiFuzzyMatchAny but returns any index that matches the haystack within a constant edit distance. Syntax
Arguments
  • haystack — String in which the search is performed. String
  • distance — The maximum edit distance for fuzzy matching. UInt8
  • pattern — Array of patterns to match against. Array(String)
Returned value Returns the index (starting from 1) of any pattern that matches the haystack within the specified edit distance, otherwise 0. UInt64 Examples Usage example
Query
Response

multiMatchAllIndices

Introduced in: v20.1.0 Like multiMatchAny but returns the array of all indices that match the haystack in any order. Syntax
Arguments
  • haystack — String in which the search is performed. String
  • pattern — Regular expressions to match against. String
Returned value Array of all indices (starting from 1) that match the haystack in any order. Returns an empty array if no matches are found. Array(UInt64) Examples Usage example
Query
Response

multiMatchAny

Introduced in: v20.1.0 Check if at least one of multiple regular expression patterns matches a haystack. If you only want to search multiple substrings in a string, you can use function multiSearchAny instead - it works much faster than this function. Syntax
Arguments
  • haystack — String in which patterns are searched. String
  • pattern1[, pattern2, ...] — An array of one or more regular expression patterns. Array(String)
Returned value Returns 1 if any pattern matches, 0 otherwise. UInt8 Examples Multiple pattern matching
Query
Response
No patterns match
Query
Response

multiMatchAnyIndex

Introduced in: v20.1.0 Like multiMatchAny but returns any index that matches the haystack. Syntax
Arguments
  • haystack — String in which the search is performed. String
  • pattern — Regular expressions to match against. Array(String)
Returned value Returns the index (starting from 1) of the first pattern that matches, or 0 if no match is found. UInt64 Examples Usage example
Query
Response

multiSearchAllPositions

Introduced in: v20.1.0 Like position but returns an array of positions (in bytes, starting at 1) for multiple needle substrings in a haystack string. All multiSearch*() functions only support up to 2^8 needles. Syntax
Arguments
  • haystack — String in which the search is performed. String
  • needle1[, needle2, ...] — An array of one or more substrings to be searched. Array(String)
Returned value Returns array of the starting position in bytes and counting from 1, if the substring was found, 0, if the substring was not found. Array(UInt64) Examples Multiple needle search
Query
Response

multiSearchAllPositionsCaseInsensitive

Introduced in: v20.1.0 Like multiSearchAllPositions but ignores case. Syntax
Arguments
  • haystack — String in which the search is performed. String
  • needle1[, needle2, ...] — An array of one or more substrings to be searched. Array(String)
Returned value Returns array of the starting position in bytes and counting from 1 (if the substring was found), 0 if the substring was not found. Array(UInt64) Examples Case insensitive multi-search
Query
Response

multiSearchAllPositionsCaseInsensitiveUTF8

Introduced in: v20.1.0 Like multiSearchAllPositionsUTF8 but ignores case. Syntax
Arguments
  • haystack — UTF-8 encoded string in which the search is performed. String
  • needle — UTF-8 encoded substrings to be searched. Array(String)
Returned value Array of the starting position in bytes and counting from 1 (if the substring was found). Returns 0 if the substring was not found. Array Examples Case-insensitive UTF-8 search
Query
Response

multiSearchAllPositionsUTF8

Introduced in: v20.1.0 Like multiSearchAllPositions but assumes haystack and the needle substrings are UTF-8 encoded strings. Syntax
Arguments
  • haystack — UTF-8 encoded string in which the search is performed. String
  • needle1[, needle2, ...] — An array of UTF-8 encoded substrings to be searched. Array(String)
Returned value Returns array of the starting position in bytes and counting from 1 (if the substring was found), 0 if the substring was not found. Array Examples UTF-8 multi-search
Query
Response

multiSearchAny

Introduced in: v20.1.0 Checks if at least one of a number of needle strings matches the haystack string. Functions multiSearchAnyCaseInsensitive, multiSearchAnyUTF8 and multiSearchAnyCaseInsensitiveUTF8 provide case-insensitive and/or UTF-8 variants of this function. Syntax
Arguments
  • haystack — String in which the search is performed. String
  • needle1[, needle2, ...] — An array of substrings to be searched. Array(String)
Returned value Returns 1, if there was at least one match, otherwise 0, if there was not at least one match. UInt8 Examples Any match search
Query
Response

multiSearchAnyCaseInsensitive

Introduced in: v20.1.0 Like multiSearchAny but ignores case. Syntax
Arguments
  • haystack — String in which the search is performed. String
  • needle — Substrings to be searched. Array(String)
Returned value Returns 1, if there was at least one case-insensitive match, otherwise 0, if there was not at least one case-insensitive match. UInt8 Examples Case insensitive search
Query
Response

multiSearchAnyCaseInsensitiveUTF8

Introduced in: v20.1.0 Like multiSearchAnyUTF8 but ignores case. Syntax
Arguments
  • haystack — UTF-8 string in which the search is performed. String
  • needle — UTF-8 substrings to be searched. Array(String)
Returned value Returns 1, if there was at least one case-insensitive match, otherwise 0, if there was not at least one case-insensitive match. UInt8 Examples Given a UTF-8 string ‘Здравствуйте’, check if character ‘з’ (lowercase) is present
Query
Response

multiSearchAnyUTF8

Introduced in: v20.1.0 Like multiSearchAny but assumes haystack and the needle substrings are UTF-8 encoded strings. Syntax
Arguments
  • haystack — UTF-8 string in which the search is performed. String
  • needle — UTF-8 substrings to be searched. Array(String)
Returned value Returns 1, if there was at least one match, otherwise 0, if there was not at least one match. UInt8 Examples Given ‘你好,世界’ (‘Hello, world’) as a UTF-8 string, check if there are any 你 or 界 characters in the string
Query
Response

multiSearchFirstIndex

Introduced in: v20.1.0 Searches for multiple needle strings in a haystack string (case-sensitive) and returns the 1-based index of the first needle found. Syntax
Arguments
  • haystack — The string to search in. String
  • needles — Array of strings to search for. Array(String)
Returned value Returns the 1-based index (position in the needles array) of the first needle found in the haystack. Returns 0 if no needles are found. The search is case-sensitive. UInt64 Examples Usage example
Query
Response
Case-sensitive behavior
Query
Response
No match found
Query
Response

multiSearchFirstIndexCaseInsensitive

Introduced in: v20.1.0 Returns the index i (starting from 1) of the leftmost found needle_i in the string haystack and 0 otherwise. Ignores case. Syntax
Arguments
  • haystack — String in which the search is performed. String
  • needle — Substrings to be searched. Array(String)
Returned value Returns the index (starting from 1) of the leftmost found needle. Otherwise 0, if there was no match. UInt8 Examples Usage example
Query
Response

multiSearchFirstIndexCaseInsensitiveUTF8

Introduced in: v20.1.0 Searches for multiple needle strings in a haystack string, case-insensitively with UTF-8 encoding support, and returns the 1-based index of the first needle found. Syntax
Arguments
  • haystack — The string to search in. String
  • needles — Array of strings to search for. Array(String)
Returned value Returns the 1-based index (position in the needles array) of the first needle found in the haystack. Returns 0 if no needles are found. The search is case-insensitive and respects UTF-8 character encoding. UInt64 Examples Usage example
Query
Response
UTF-8 case handling
Query
Response
No match found
Query
Response

multiSearchFirstIndexUTF8

Introduced in: v20.1.0 Returns the index i (starting from 1) of the leftmost found needle_i in the string haystack and 0 otherwise. Assumes haystack and needle are UTF-8 encoded strings. Syntax
Arguments
  • haystack — UTF-8 string in which the search is performed. String
  • needle — Array of UTF-8 substrings to be searched. Array(String)
Returned value Returns the index (starting from 1) of the leftmost found needle. Otherwise 0, if there was no match. UInt8 Examples Usage example
Query
Response

multiSearchFirstPosition

Introduced in: v20.1.0 Like position but returns the leftmost offset in a haystack string which matches any of multiple needle strings. Functions multiSearchFirstPositionCaseInsensitive, multiSearchFirstPositionUTF8 and multiSearchFirstPositionCaseInsensitiveUTF8 provide case-insensitive and/or UTF-8 variants of this function. Syntax
Arguments
  • haystack — String in which the search is performed. String
  • needle1[, needle2, ...] — An array of one or more substrings to be searched. Array(String)
Returned value Returns the leftmost offset in a haystack string which matches any of multiple needle strings, otherwise 0, if there was no match. UInt64 Examples First position search
Query
Response

multiSearchFirstPositionCaseInsensitive

Introduced in: v20.1.0 Like multiSearchFirstPosition but ignores case. Syntax
Arguments
  • haystack — String in which the search is performed. String
  • needle — Array of substrings to be searched. Array(String)
Returned value Returns the leftmost offset in a haystack string which matches any of multiple needle strings. Returns 0, if there was no match. UInt64 Examples Case insensitive first position
Query
Response

multiSearchFirstPositionCaseInsensitiveUTF8

Introduced in: v20.1.0 Like multiSearchFirstPosition but assumes haystack and needle to be UTF-8 strings and ignores case. Syntax
Arguments
  • haystack — UTF-8 string in which the search is performed. String
  • needle — Array of UTF-8 substrings to be searched. Array(String)
Returned value Returns the leftmost offset in a haystack string which matches any of multiple needle strings, ignoring case. Returns 0, if there was no match. UInt64 Examples Find the leftmost offset in UTF-8 string ‘Здравствуй, мир’ (‘Hello, world’) which matches any of the given needles
Query
Response

multiSearchFirstPositionUTF8

Introduced in: v20.1.0 Like multiSearchFirstPosition but assumes haystack and needle to be UTF-8 strings. Syntax
Arguments
  • haystack — UTF-8 string in which the search is performed. String
  • needle — Array of UTF-8 substrings to be searched. Array(String)
Returned value Leftmost offset in a haystack string which matches any of multiple needle strings. Returns 0, if there was no match. UInt64 Examples Find the leftmost offset in UTF-8 string ‘Здравствуй, мир’ (‘Hello, world’) which matches any of the given needles
Query
Response

ngramDistance

Introduced in: v20.1.0 Calculates the 4-gram distance between two strings. For this, it counts the symmetric difference between two multisets of 4-grams and normalizes it by the sum of their cardinalities. The smaller the returned value, the more similar the strings are. For case-insensitive search or/and in UTF8 format use functions ngramDistanceCaseInsensitive, ngramDistanceUTF8, ngramDistanceCaseInsensitiveUTF8. Syntax
Arguments
  • haystack — String for comparison. String
  • needle — String for comparison. String
Returned value Returns a Float32 number between 0 and 1. The smaller the returned value, the more similar the strings are. Float32 Examples Calculate 4-gram distance
Query
Response

ngramDistanceCaseInsensitive

Introduced in: v20.1.0 Provides a case-insensitive variant of ngramDistance. Calculates the 4-gram distance between two strings, ignoring case. The smaller the returned value, the more similar the strings are. Syntax
Arguments
  • haystack — First comparison string. String
  • needle — Second comparison string. String
Returned value Returns a Float32 number between 0 and 1. Float32 Examples Case-insensitive 4-gram distance
Query
Response

ngramDistanceCaseInsensitiveUTF8

Introduced in: v20.1.0 Provides a case-insensitive UTF-8 variant of ngramDistance. Assumes that needle and haystack strings are UTF-8 encoded strings and ignores case. Calculates the 3-gram distance between two UTF-8 strings, ignoring case. The smaller the returned value, the more similar the strings are. Syntax
Arguments
  • haystack — First UTF-8 encoded comparison string. String
  • needle — Second UTF-8 encoded comparison string. String
Returned value Returns a Float32 number between 0 and 1. Float32 Examples Case-insensitive UTF-8 3-gram distance
Query
Response

ngramDistanceUTF8

Introduced in: v20.1.0 Provides a UTF-8 variant of ngramDistance. Assumes that needle and haystack strings are UTF-8 encoded strings. Calculates the 3-gram distance between two UTF-8 strings. The smaller the returned value, the more similar the strings are. Syntax
Arguments
  • haystack — First UTF-8 encoded comparison string. String
  • needle — Second UTF-8 encoded comparison string. String
Returned value Returns a Float32 number between 0 and 1. Float32 Examples UTF-8 3-gram distance
Query
Response

ngramSearch

Introduced in: v20.1.0 Checks if the 4-gram distance between two strings is less than or equal to a given threshold. For case-insensitive search or/and in UTF8 format use functions ngramSearchCaseInsensitive, ngramSearchUTF8, ngramSearchCaseInsensitiveUTF8. Syntax
Arguments
  • haystack — String for comparison. String
  • needle — String for comparison. String
Returned value Returns 1 if the 4-gram distance between the strings is less than or equal to a threshold (1.0 by default), 0 otherwise. UInt8 Examples Search using 4-grams
Query
Response

ngramSearchCaseInsensitive

Introduced in: v20.1.0 Provides a case-insensitive variant of ngramSearch. Calculates the non-symmetric difference between a needle string and a haystack string, i.e. the number of n-grams from the needle minus the common number of n-grams normalized by the number of needle n-grams. Checks if the 4-gram distance between two strings is less than or equal to a given threshold, ignoring case. Syntax
Arguments
  • haystack — String for comparison. String
  • needle — String for comparison. String
Returned value Returns 1 if the 4-gram distance between the strings is less than or equal to a threshold (1.0 by default), 0 otherwise. UInt8 Examples Case-insensitive search using 4-grams
Query
Response

ngramSearchCaseInsensitiveUTF8

Introduced in: v20.1.0 Provides a case-insensitive UTF-8 variant of ngramSearch. Assumes haystack and needle to be UTF-8 strings and ignores case. Checks if the 3-gram distance between two UTF-8 strings is less than or equal to a given threshold, ignoring case. Syntax
Arguments
  • haystack — UTF-8 string for comparison. String
  • needle — UTF-8 string for comparison. String
Returned value Returns 1 if the 3-gram distance between the strings is less than or equal to a threshold (1.0 by default), 0 otherwise. UInt8 Examples Case-insensitive UTF-8 search using 3-grams
Query
Response

ngramSearchUTF8

Introduced in: v20.1.0 Provides a UTF-8 variant of ngramSearch. Assumes haystack and needle to be UTF-8 strings. Checks if the 3-gram distance between two UTF-8 strings is less than or equal to a given threshold. Syntax
Arguments
  • haystack — UTF-8 string for comparison. String
  • needle — UTF-8 string for comparison. String
Returned value Returns 1 if the 3-gram distance between the strings is less than or equal to a threshold (1.0 by default), 0 otherwise. UInt8 Examples UTF-8 search using 3-grams
Query
Response

notILike

Introduced in: v20.6.0 Checks whether a string does not match a pattern, case-insensitive. The pattern can contain special characters % and _ for SQL LIKE matching. Supports the optional ESCAPE clause (see like). Syntax
Arguments
  • haystack — The input string to search in. String or FixedString
  • pattern — The SQL LIKE pattern to match against. % matches any number of characters (including zero), _ matches exactly one character. String
  • escape_character — Optional single-character string to use as the escape character instead of \. Default: \. String
Returned value Returns 1 if the string does not match the pattern (case-insensitive), otherwise 0. UInt8 Examples Usage example
Query
Response

notLike

Introduced in: v1.1.0 Similar to like but negates the result. Supports the optional ESCAPE clause (see like). Syntax
Arguments
  • haystack — String in which the search is performed. String or FixedString
  • pattern — LIKE pattern to match against. String
  • escape_character — Optional single-character string to use as the escape character instead of \. Default: \. String
Returned value Returns 1 if the string does not match the LIKE pattern, otherwise 0. UInt8 Examples Usage example
Query
Response
Non-matching pattern
Query
Response

position

Introduced in: v1.1.0 Returns the position (in bytes, starting at 1) of a substring needle in a string haystack. If substring needle is empty, these rules apply:
  • if no start_pos was specified: return 1
  • if start_pos = 0: return 1
  • if start_pos >= 1 and start_pos <= length(haystack) + 1: return start_pos
  • otherwise: return 0
The same rules also apply to functions locate, positionCaseInsensitive, positionUTF8 and positionCaseInsensitiveUTF8. Syntax
Arguments
  • haystack — String in which the search is performed. String or Enum
  • needle — Substring to be searched. String
  • start_pos — Position (1-based) in haystack at which the search starts. Optional. UInt
Returned value Returns starting position in bytes and counting from 1, if the substring was found, otherwise 0, if the substring was not found. UInt64 Examples Basic usage
Query
Response
With start_pos argument
Query
Response
Needle IN haystack syntax
Query
Response
Empty needle substring
Query
Response

positionCaseInsensitive

Introduced in: v1.1.0 Like position but case-insensitive. Syntax
Aliases: instr Arguments
  • haystack — String in which the search is performed. String or Enum
  • needle — Substring to be searched. String
  • start_pos — Optional. Position (1-based) in haystack at which the search starts. UInt*
Returned value Returns starting position in bytes and counting from 1, if the substring was found, otherwise 0, if the substring was not found. UInt64 Examples Case insensitive search
Query
Response

positionCaseInsensitiveUTF8

Introduced in: v1.1.0 Like positionUTF8 but searches case-insensitively. Syntax
Arguments
  • haystack — String in which the search is performed. String or Enum
  • needle — Substring to be searched. String
  • start_pos — Optional. Position (1-based) in haystack at which the search starts. UInt*
Returned value Returns starting position in bytes and counting from 1, if the substring was found, otherwise 0, if the substring was not found. UInt64 Examples Case insensitive UTF-8 search
Query
Response

positionUTF8

Introduced in: v1.1.0 Like position but assumes haystack and needle are UTF-8 encoded strings. Syntax
Arguments
  • haystack — String in which the search is performed. String or Enum
  • needle — Substring to be searched. String
  • start_pos — Optional. Position (1-based) in haystack at which the search starts. UInt*
Returned value Returns starting position in bytes and counting from 1, if the substring was found, otherwise 0, if the substring was not found. UInt64 Examples UTF-8 character counting
Query
Response
Last modified on July 1, 2026