split

Splits a given string with a given separator and returns the result in an array of strings.

Contiguous split strings in the source string, or the presence of a split string at the beginning or end of the source string, results in an empty string in the output. An empty separator string results in an array containing only the source string. If either parameter is a NULL, a NULL is returned.

Syntax

split(<string>, <separator>)

Arguments

<string>

Text to be split into parts.

<separator> (named)

Text to split string by.

Returns

The data type of the returned value is ARRAY.

Examples

Split a dotted version string into an array consisting of each part:

SELECT split('1.2.3.4', '.');
+-----------------------+
| split('1.2.3.4', '.') |
+-----------------------+
| ['1','2','3','4']     |
+-----------------------+

Split a string that contains vertical lines as separators (note that the output will contain empty strings):

SELECT split('|a||', '|');
+--------------------+
| split('|a||', '|') |
+--------------------+
| ['','a','','']     |
+--------------------+