ClickHouse/docs/en/sql-reference/statements/select/into-outfile.md
Nikolay Degterinsky 54d210d714 Add documentation
2022-07-07 01:59:00 +00:00

1.6 KiB

sidebar_label
INTO OUTFILE

INTO OUTFILE Clause

INTO OUTFILE clause redirects the result of a SELECT query to a file on the client side.

Compressed files are supported. Compression type is detected by the extension of the file name (mode 'auto' is used by default). Or it can be explicitly specified in a COMPRESSION clause. Compression level for a certain compression type can be specified in a LEVEL clause.

Syntax

SELECT <expr_list> INTO OUTFILE file_name [COMPRESSION type [LEVEL level]]

file_name and type are string literals. Supported compression types are: 'none', 'gzip', 'deflate', 'br', 'xz', 'zstd', 'lz4', 'bz2'.

level is a numeric literal. Positive integers in following ranges are supported: 1-12 for lz4 type, 1-22 for zstd type and 1-9 for other compression types.

Implementation Details

Example

Execute the following query using command-line client:

clickhouse-client --query="SELECT 1,'ABC' INTO OUTFILE 'select.gz' FORMAT CSV;"
zcat select.gz 

Result:

1,"ABC"