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

> 테이블 함수에 대한 문서

# 테이블 함수

테이블 함수는 테이블을 생성하는 방법입니다.

<div id="usage">
  ## 사용법
</div>

테이블 함수는 `SELECT` 쿼리의 [`FROM`](/docs/ko/reference/statements/select/from)
절에서 사용할 수 있습니다. 예를 들어, `file` 테이블 함수를 사용하면 로컬
머신의 파일에서 데이터를 `SELECT`할 수 있습니다.

```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 │
└────┴────┴────┘
```

현재 쿼리에서만 사용 가능한 임시 테이블을 생성할 때도 테이블 함수를 사용할 수
있습니다. 예시:

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

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

테이블은 쿼리가 종료되면 삭제됩니다.

테이블 함수는 다음 구문을 사용해 테이블을 생성하는 데 사용할 수 있습니다:

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

예시:

```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 │
└─────────────────┘
```

마지막으로, 테이블 함수를 사용해 테이블에 데이터를 `INSERT`할 수 있습니다. 예를 들어,
이전 예시에서 생성한 테이블의 내용을 다시 `file` 테이블 함수를 사용해
디스크의 파일에 기록할 수 있습니다:

```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>
  [allow\_ddl](/docs/ko/reference/settings/session-settings#allow_ddl) 설정이 비활성화된 경우 테이블 함수를 사용할 수 없습니다.
</Note>
