Skip to main content
Splits a string into an array of strings based on a specified delimiter, with the following behaviors:
  • If the delimiter is an empty string '', the result is an array containing the entire original input string as a single element.
  • If the delimiter is NULL, the string is split into individual characters, with one character per array element.

Syntax

STRING_TO_ARRAY(<string>, <delimiter>)

Parameters

ParameterDescription
<string>The string to split.
<delimiter>The separator to split the string by.

Return Types

ARRAY(TEXT)

Examples

Example The following code example splits the string stephen70|esimpson|ruthgill| at each | character and returns the resulting array as nicknames:
SELECT STRING_TO_ARRAY('stephen70|esimpson|ruthgill|', '|') AS nicknames;
nicknames array(text)
[‘stephen70’, ‘esimpson’, ‘ruthgill’, ”]

Rows: 1Execution time: 5.37ms

Example The following code example calls STRING_TO_ARRAY with an empty delimiter, producing an array containing a single element which contains the input text:
SELECT STRING_TO_ARRAY('firebolt', '') AS size_one_array;
size_one_array array(text)
[‘firebolt’]

Rows: 1Execution time: 7.91ms

Example The following example calls STRING_TO_ARRAY with NULL as the delimiter, splitting the text into individual characters:
SELECT STRING_TO_ARRAY('firebolt', NULL) AS single_characters;
single_characters array(text)
[‘f’, ‘i’, ‘r’, ‘e’, ‘b’, ‘o’, ‘l’, ‘t’]

Rows: 1Execution time: 5.72ms