# csv_extract function
Returns separated values from a column containing a CSV file formatted as a string.

> For the complete documentation index, see [llms.txt](https://preview.materialize.com/materialize/40269/llms.txt).


`csv_extract` returns individual component columns from a column containing a CSV file formatted as a string.

## Signatures



```mzsql
csv_extract ( <num_csv_col>, <col_name> )

```

| Syntax element | Description |
| --- | --- |
| `<num_csv_col>` | An [`int`](https://preview.materialize.com/materialize/40269/markdown-docs/sql/types/integer/index.md) value specifying the number of columns in the CSV string.  |
| `<col_name>` | A [`string`](https://preview.materialize.com/materialize/40269/markdown-docs/sql/types/text/index.md) value containing the name of the column containing the CSV string.  |


Parameter | Type | Description
----------|------|------------
_num_csv_col_ | [`int`](https://preview.materialize.com/materialize/40269/markdown-docs/sql/types/integer/index.md) | The number of columns in the CSV string.
_col_name_  | [`string`](https://preview.materialize.com/materialize/40269/markdown-docs/sql/types/text/index.md)  | The name of the column containing the CSV string.

### Return value

`EXTRACT` returns [`string`](https://preview.materialize.com/materialize/40269/markdown-docs/sql/types/text/index.md) columns.

## Example

Create a table where one column is in CSV format and insert some rows:

```mzsql
CREATE TABLE t (id int, data string);
INSERT INTO t
  VALUES (1, 'some,data'), (2, 'more,data'), (3, 'also,data');
```

Extract the component columns from the table column which is a CSV string, sorted by column `id`:

```mzsql
SELECT csv.* FROM t, csv_extract(2, data) csv
  ORDER BY t.id;
```
```nofmt
 column1 | column2
---------+---------
 also    | data
 more    | data
 some    | data
(3 rows)
```
