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

> INTO OUTFILE 절 문서

# INTO OUTFILE 절

`INTO OUTFILE` 절은 `SELECT` 쿼리 결과를 **클라이언트** 측의 파일로 출력합니다.

압축 파일도 지원됩니다. 압축 유형은 파일 이름의 확장자로 감지되며(기본적으로 `'auto'` 모드 사용), `COMPRESSION` 절에서 명시적으로 지정할 수도 있습니다. 특정 압축 유형의 압축 수준은 `LEVEL` 절에서 지정할 수 있습니다.

**구문**

```sql theme={null}
SELECT <expr_list> INTO OUTFILE file_name [AND STDOUT] [APPEND | TRUNCATE] [COMPRESSION type [LEVEL level]]
```

`file_name` 및 `type`은 문자열 리터럴입니다. 지원되는 압축 타입은 `'none'`, `'gzip'`, `'deflate'`, `'br'`, `'xz'`, `'zstd'`, `'lz4'`, `'bz2'`입니다.

`level`은 숫자 리터럴입니다. 다음 범위의 양의 정수를 지원합니다: `lz4` 타입은 `1-12`, `zstd` 타입은 `1-22`, 기타 압축 타입은 `1-9`입니다.

<div id="implementation-details">
  ## 구현 세부 정보
</div>

* 이 기능은 [command-line client](/ko/concepts/features/interfaces/client)와 [clickhouse-local](/ko/concepts/features/tools-and-utilities/clickhouse-local)에서 사용할 수 있습니다. 따라서 [HTTP 인터페이스](/ko/concepts/features/interfaces/http)를 통해 전송한 쿼리는 실패합니다.
* 같은 파일 이름의 파일이 이미 있으면 쿼리가 실패합니다.
* 기본 [출력 형식](/ko/reference/formats/index)은 `TabSeparated`입니다(command-line client의 batch mode와 동일). 변경하려면 [FORMAT](/ko/reference/statements/select/format) 절을 사용하십시오.
* 쿼리에 `AND STDOUT`이 포함되면 파일에 기록되는 출력이 표준 출력에도 표시됩니다. 압축과 함께 사용할 경우 평문이 표준 출력에 표시됩니다.
* 쿼리에 `APPEND`가 포함되면 출력이 기존 파일에 추가됩니다. 압축을 사용하는 경우 `APPEND`는 사용할 수 없습니다.
* 이미 존재하는 파일에 쓸 때는 `APPEND` 또는 `TRUNCATE`를 사용해야 합니다.

**예시**

다음 쿼리를 [command-line client](/ko/concepts/features/interfaces/client)에서 실행하십시오:

```bash title="Query" theme={null}
clickhouse-client --query="SELECT 1,'ABC' INTO OUTFILE 'select.gz' FORMAT CSV;"
zcat select.gz 
```

```text title="Response" theme={null}
1,"ABC"
```
