ClickHouse/docs/en/query_language/functions/splitting_merging_functions.md

110 lines
3.5 KiB
Markdown
Raw Normal View History

2020-03-20 10:10:48 +00:00
# Functions for splitting and merging strings and arrays {#functions-for-splitting-and-merging-strings-and-arrays}
2020-03-20 10:10:48 +00:00
## splitByChar(separator, s) {#splitbycharseparator-s}
Splits a string into substrings separated by a specified character. It uses a constant string `separator` which consisting of exactly one character.
Returns an array of selected substrings. Empty substrings may be selected if the separator occurs at the beginning or end of the string, or if there are multiple consecutive separators.
**Syntax**
```sql
splitByChar(<separator>, <s>)
```
**Parameters**
- `separator` — The separator which should contain exactly one character. [String](../../data_types/string.md).
- `s` — The string to split. [String](../../data_types/string.md).
**Returned value(s)**
Returns an array of selected substrings. Empty substrings may be selected when:
* A separator occurs at the beginning or end of the string;
* There are multiple consecutive separators;
* The original string `s` is empty.
Type: [Array](../../data_types/array.md) of [String](../../data_types/string.md).
**Example**
2020-03-20 10:10:48 +00:00
``` sql
SELECT splitByChar(',', '1,2,3,abcde')
```
2020-03-20 10:10:48 +00:00
``` text
┌─splitByChar(',', '1,2,3,abcde')─┐
│ ['1','2','3','abcde'] │
└─────────────────────────────────┘
```
2020-03-20 10:10:48 +00:00
## splitByString(separator, s) {#splitbystringseparator-s}
Splits a string into substrings separated by a string. It uses a constant string `separator` of multiple characters as the separator. If the string `separator` is empty, it will split the string `s` into an array of single characters.
**Syntax**
```sql
splitByString(<separator>, <s>)
```
**Parameters**
- `separator` — The separator. [String](../../data_types/string.md).
- `s` — The string to split. [String](../../data_types/string.md).
**Returned value(s)**
Returns an array of selected substrings. Empty substrings may be selected when:
2020-03-20 18:36:14 +00:00
Type: [Array](../../data_types/array.md) of [String](../../data_types/string.md).
* A non-empty separator occurs at the beginning or end of the string;
* There are multiple consecutive non-empty separators;
* The original string `s` is empty while the separator is not empty.
**Example**
2020-03-20 10:10:48 +00:00
``` sql
SELECT splitByString(', ', '1, 2 3, 4,5, abcde')
```
2020-03-20 10:10:48 +00:00
``` text
┌─splitByString(', ', '1, 2 3, 4,5, abcde')─┐
│ ['1','2 3','4,5','abcde'] │
└───────────────────────────────────────────┘
```
2020-03-20 10:10:48 +00:00
``` sql
SELECT splitByString('', 'abcde')
```
2020-03-20 10:10:48 +00:00
``` text
┌─splitByString('', 'abcde')─┐
│ ['a','b','c','d','e'] │
└────────────────────────────┘
```
2020-03-20 10:10:48 +00:00
## arrayStringConcat(arr\[, separator\]) {#arraystringconcatarr-separator}
2020-03-20 10:10:48 +00:00
Concatenates the strings listed in the array with the separator.separator is an optional parameter: a constant string, set to an empty string by default.
Returns the string.
2020-03-20 10:10:48 +00:00
## alphaTokens(s) {#alphatokenss}
Selects substrings of consecutive bytes from the ranges a-z and A-Z.Returns an array of substrings.
**Example**
2020-03-20 10:10:48 +00:00
``` sql
SELECT alphaTokens('abca1abc')
DOCAPI-8530: Code blocks markup fix (#7060) * Typo fix. * Links fix. * Fixed links in docs. * More fixes. * docs/en: cleaning some files * docs/en: cleaning data_types * docs/en: cleaning database_engines * docs/en: cleaning development * docs/en: cleaning getting_started * docs/en: cleaning interfaces * docs/en: cleaning operations * docs/en: cleaning query_lamguage * docs/en: cleaning en * docs/ru: cleaning data_types * docs/ru: cleaning index * docs/ru: cleaning database_engines * docs/ru: cleaning development * docs/ru: cleaning general * docs/ru: cleaning getting_started * docs/ru: cleaning interfaces * docs/ru: cleaning operations * docs/ru: cleaning query_language * docs: cleaning interfaces/http * Update docs/en/data_types/array.md decorated ``` Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/getting_started/example_datasets/nyc_taxi.md fixed typo Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/getting_started/example_datasets/ontime.md fixed typo Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/interfaces/formats.md fixed error Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/operations/table_engines/custom_partitioning_key.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/operations/utils/clickhouse-local.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/query_language/dicts/external_dicts_dict_sources.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/operations/utils/clickhouse-local.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/query_language/functions/json_functions.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/query_language/functions/json_functions.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/query_language/functions/other_functions.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/query_language/functions/other_functions.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/query_language/functions/date_time_functions.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * Update docs/en/operations/table_engines/jdbc.md Co-Authored-By: BayoNet <da-daos@yandex.ru> * docs: fixed error * docs: fixed error
2019-09-23 15:31:46 +00:00
```
2020-03-20 10:10:48 +00:00
``` text
┌─alphaTokens('abca1abc')─┐
│ ['abca','abc'] │
└─────────────────────────┘
```
2020-03-20 10:10:48 +00:00
2020-01-30 10:34:55 +00:00
[Original article](https://clickhouse.tech/docs/en/query_language/functions/splitting_merging_functions/) <!--hide-->