# split

[Read this page in HTML](https://www.scopedb.io/docs/reference/functions/string/split)

Splits a string into an array of substrings.

## Syntax

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

## Arguments

| Argument    | Type     | Description                                               |
| ----------- | -------- | --------------------------------------------------------- |
| `<string>`  | `string` | String to split.                                          |
| `separator` | `string` | Constant. 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`:

```scopeql
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
```

```text
+----------+-------------------+
| 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.

```scopeql
SELECT split('checkout||failed', separator => '|') AS fields
```

```text
+--------------------------+
| fields                   |
+--------------------------+
| ["checkout","","failed"] |
+--------------------------+
```
