split

Splits a string into an array of substrings.

Syntax

split(<string>, separator => <separator>)

Arguments

ArgumentTypeDescription
<string>stringString to split.
separatorstringConstant. Delimiter between substrings. Must not be NULL.

Returns

Returns an array of strings, or NULL for a NULL input.

  • Leading, trailing, and adjacent delimiters produce empty elements.
  • An empty separator splits between Unicode characters and adds an empty element at each end.

Examples

Turn event labels into an array

Split comma-separated product categories, then select orders containing gifts:

VALUES ('o-17', 'books,gifts'), ('o-42', 'electronics'), ('o-63', 'gifts,home')
SELECT $0 AS order_id, split($1, separator => ',') AS categories
WHERE contains(categories, 'gifts')
SELECT order_id, categories
ORDER BY order_id
+----------+-------------------+
| order_id | categories        |
+----------+-------------------+
| o-17     | ["books","gifts"] |
| o-63     | ["gifts","home"]  |
+----------+-------------------+

split separates on literal delimiters; it does not implement quoted CSV parsing.

Inspect incomplete delimited fields

Preserved empty elements help reveal missing values in an imported three-field record.

SELECT split('checkout||failed', separator => '|') AS fields
+--------------------------+
| fields                   |
+--------------------------+
| ["checkout","","failed"] |
+--------------------------+