> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-parallel-read-in-order-multi-part.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Documentation for Table Functions

# Table Functions

Table functions are methods for constructing tables.

<h2 id="usage">
  Usage
</h2>

Table functions can be used in the [`FROM`](/reference/statements/select/from)
clause of a `SELECT` query. For example, you can `SELECT` data from a file on your local
machine using the `file` table function.

```bash title="Query" theme={null}
echo "1, 2, 3" > example.csv
```

```text title="Response" theme={null}
./clickhouse client
:) SELECT * FROM file('example.csv')
┌─c1─┬─c2─┬─c3─┐
│  1 │  2 │  3 │
└────┴────┴────┘
```

You can also use table functions for creating a temporary table that is available
only in the current query. For example:

```sql title="Query" theme={null}
SELECT * FROM generateSeries(1,5);
```

```response title="Response" theme={null}
┌─generate_series─┐
│               1 │
│               2 │
│               3 │
│               4 │
│               5 │
└─────────────────┘
```

The table is deleted when the query finishes.

Table functions can be used as a way to create tables, using the following syntax:

```sql title="Query" theme={null}
CREATE TABLE [IF NOT EXISTS] [db.]table_name AS table_function()
```

For example:

```sql title="Query" theme={null}
CREATE TABLE series AS generateSeries(1, 5);
SELECT * FROM series;
```

```response title="Response" theme={null}
┌─generate_series─┐
│               1 │
│               2 │
│               3 │
│               4 │
│               5 │
└─────────────────┘
```

Finally, table functions can be used to `INSERT` data into a table. For example,
we could write out the contents of the table we created in the previous example
to a file on disk using the `file` table function again:

```sql title="Query" theme={null}
INSERT INTO FUNCTION file('numbers.csv', 'CSV') SELECT * FROM series;
```

```bash title="Query" theme={null}
cat numbers.csv
1
2
3
4
5
```

<Note>
  Most table functions need the `CREATE TEMPORARY TABLE` privilege to run, so a `SELECT` or `INSERT`
  that executes one is refused when
  [`readonly`](/concepts/features/configuration/settings/permissions-for-queries#readonly) is set to 1.
</Note>
