Splits a string into an array of substrings using a specified delimiter. Contiguous delimiters produce empty strings in the result. If any parameter is NULL, the function returns NULL.
Syntax
ARRAY<STRING> SPLIT(STRING <source>, STRING <delimiter>[, BOOLEAN <trimTailEmpty>])Quick example
-- Returns ["a","b","c"].
SELECT SPLIT('a,b,c', ',');Parameters
source: Required. The
STRINGto split.delimiter: Required. The separator pattern. Accepts a plain string or a regular expression.
trimTailEmpty: Optional. A
BOOLEANthat controls whether trailing empty strings are kept. When the source string ends with one or more consecutive delimiters, those delimiters produce empty strings at the tail of the result array. Use this parameter to discard or retain them.true(default): Removes trailing empty strings.false: Retains trailing empty strings.
Return value
Returns ARRAY<STRING>.
Examples
Example 1: Split by a comma
-- Returns ["a","b","c"].
SELECT SPLIT('a,b,c', ',');Example 2: Delimiter not found
-- Returns ["a,b,c"].
SELECT SPLIT('a,b,c', ':');Example 3: Consecutive delimiters
-- Returns ["a", "", "b"].
SELECT SPLIT('a,,b', ',');Example 4: Multi-character delimiter
-- Returns ["a","b","c"].
SELECT SPLIT('a::b::c', '::');Example 5: Controlling trailing empty strings
-- trimTailEmpty defaults to true, so trailing empty strings are discarded.
-- Returns ["a","b","c"].
SELECT SPLIT('a,b,c,,', ',');
-- Set to false to retain trailing empty strings.
-- Returns ["a", "b", "c", "", ""].
SELECT SPLIT('a,b,c,,', ',', false);Example 6: Special character delimiters
-- Split by a newline character.
-- Returns ["hello","world"].
SELECT SPLIT('hello\nworld', '\n');
-- Split by a tab character.
-- Returns ["a","b","c"].
SELECT SPLIT('a\tb\tc', '\t');
-- Split by a carriage return character.
-- Returns ["line1","line2"].
SELECT SPLIT('line1\rline2', '\r');
-- Split by a backslash. The delimiter must be escaped as \\\\.
-- Returns ["a","b","c"].
SELECT SPLIT('a\\b\\c', '\\\\');Example 7: NULL handling
-- If any parameter is NULL, the result is NULL.
SELECT SPLIT(NULL, ','); -- Returns NULL.
SELECT SPLIT('a,b,c', NULL); -- Returns NULL.
SELECT SPLIT('a,b,c', ',', NULL); -- Returns NULL.Related functions
SPLIT is a string function. For more string functions, see String functions.