v.21.1New Features
Implement Substring Count Functions in ClickHouse
ImplementcountSubstrings()/countSubstringsCaseInsensitive()/countSubstringsCaseInsensitiveUTF8()(Count the number of substring occurrences). #17347 (Azat Khuzhin).
Why it matters
These functions provide users with a straightforward way to count how many times a specific substring appears in a string, with support for case-sensitive and case-insensitive matching, including UTF-8 case-insensitive comparisons. This simplifies string analysis and pattern counting tasks within ClickHouse queries.How to use it
Use the functions by passing the target string and the substring to count as arguments. For example:SELECT countSubstrings('hello world, hello ClickHouse', 'hello') AS count;
SELECT countSubstringsCaseInsensitive('Hello world', 'hello') AS count;
SELECT countSubstringsCaseInsensitiveUTF8('ΠΡΠΈΠ²Π΅Ρ ΠΌΠΈΡ', 'ΠΏΡΠΈΠ²Π΅Ρ') AS count;These functions return the number of substring occurrences in the given string.