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
SELECT <expr_list> INTO OUTFILE file_name [COMPRESSION type]
type are string literals. Supported compression types are:
- This functionality is available in the command-line client and clickhouse-local. Thus a query sent via HTTP interface will fail.
- The query will fail if a file with the same file name already exists.
- The default output format is
TabSeparated(like in the command-line client batch mode). Use FORMAT clause to change it.
Execute the following query using command-line client:
clickhouse-client --query="SELECT 1,'ABC' INTO OUTFILE 'select.gz' FORMAT CSV;"