> ## Documentation Index
> Fetch the complete documentation index at: https://docs.firebolt.io/llms.txt
> Use this file to discover all available pages before exploring further.

> Reference material for SPLIT_PART function

# SPLIT_PART

Splits `<string>` at occurrences of `<delimiter>` and returns the `<index>`'th field, with 1 being the first index.
If `<index>` is negative, returns the `abs(<index>)`'th-from-last field.
If `<delimiter>` is empty, `<string>` is returned at `<index>` 1.
If `abs(<index>)` is larger than the number of fields, returns an empty string.
The function raises an error for `<index>` 0.

## Syntax

```sql theme={"theme":{"light":"css-variables","dark":"css-variables"}}
SPLIT_PART(<string>, <delimiter>, <index>)
```

## Parameters

| Parameter     | Description                                                           | Supported input types |
| :------------ | :-------------------------------------------------------------------- | :-------------------- |
| `<string>`    | The string to be split.                                               | `TEXT`                |
| `<delimiter>` | The character used to split the string.                               | `TEXT`                |
| `<index>`     | The index position of the substring to return within the split parts. | `INTEGER`             |

## Return Type

`TEXT`

## Examples

**Example**

The following code example uses the delimiter `#` to split the string `'hello#world'`, and returns the first segment:

<div className="query-window">
  ```
  SELECT SPLIT_PART('hello#world', '#', 1) AS res;
  ```

  | res <span>text</span> |
  | :-------------------- |
  | hello                 |

  <p><span>Rows: 1</span><span>Execution time: 5.03ms</span></p>
</div>

**Example**

The following code example uses the delimiter `|` to split the string `'this|is|my|test'`, and returns the second to last segment:

<div className="query-window">
  ```
  SELECT SPLIT_PART('this|is|my|test', '|', -2) AS res;
  ```

  | res <span>text</span> |
  | :-------------------- |
  | my                    |

  <p><span>Rows: 1</span><span>Execution time: 8.40ms</span></p>
</div>

**Example**

The following code example uses an empty delimiter `''` to split the string `'hello world'`, and returns the first segment. `SPLIT_PART` sees the empty delimiter and interprets the entire string as the first and only part of the string and returns 'hello world'.

<div className="query-window">
  ```
  SELECT SPLIT_PART('hello world', '', 1) AS res;
  ```

  | res <span>text</span> |
  | :-------------------- |
  | hello world           |

  <p><span>Rows: 1</span><span>Execution time: 5.17ms</span></p>
</div>

**Example**

The following code example uses an empty delimiter `''` to split the string `'hello world'`, and attempts to return the seventh segment. Because there is no seventh part, `SPLIT_PART` returns an empty string.

<div className="query-window">
  ```
  SELECT SPLIT_PART('hello world', '', 7) AS res;
  ```

  | res <span>text</span> |
  | :-------------------- |
  |                       |

  <p><span>Rows: 1</span><span>Execution time: 5.70ms</span></p>
</div>
