{"id":"48cb6186-6fcf-4500-ba08-717dfeb4e4a9","task":"Export ClickHouse query results to CSV or Parquet files with the FORMAT clause and INTO OUTFILE, then read the exported files back.","domain":"clickhouse.com","steps":["Use the FORMAT clause to control the output serialization of a SELECT, e.g. FORMAT CSV or FORMAT Parquet; without INTO OUTFILE the formatted result streams to stdout: clickhouse-client --query=\"SELECT * FROM my_table FORMAT CSV\" > out.csv","To have the client write directly to a file on the client side, append INTO OUTFILE 'path' before FORMAT: clickhouse-client --query=\"SELECT 1,'ABC' INTO OUTFILE 'select.gz' FORMAT CSV;\" — full syntax is SELECT <expr_list> INTO OUTFILE file_name [AND STDOUT] [APPEND|TRUNCATE] [COMPRESSION type [LEVEL level]].","For Parquet specifically: clickhouse-client --query=\"SELECT * FROM my_table INTO OUTFILE 'out.parquet' FORMAT Parquet;\" — the default output format (if FORMAT is omitted) is TabSeparated, so always specify FORMAT explicitly for CSV/Parquet exports.","Compress on the way out by naming the file with a known extension (auto-detected) or specifying it explicitly: ... INTO OUTFILE 'select.gz' — supported compression types are none, gzip, deflate, br, xz, zstd, lz4, bz2, with optional LEVEL (1-12 for gzip/deflate/lz4, 1-22 for zstd, 1-9 for others).","INTO OUTFILE only works from the command-line client or clickhouse-local — a query using INTO OUTFILE sent over the plain HTTP interface will fail; for HTTP exports, instead request FORMAT CSV/Parquet in the query and redirect curl's response to a file, e.g. curl \"http://localhost:8123/?query=SELECT...FORMAT+Parquet\" -o out.parquet.","Read an exported CSV/Parquet file back into ClickHouse using the file() table function or by loading it with clickhouse-local: SELECT * FROM file('out.parquet', 'Parquet'); or for a server, INSERT INTO my_table SELECT * FROM file('out.csv', 'CSV').","If the target output file already exists, the query fails unless you add APPEND or TRUNCATE (APPEND cannot be combined with COMPRESSION).","Reference: https://clickhouse.com/docs/sql-reference/statements/select/into-outfile"],"gotchas":["INTO OUTFILE is a client-side feature of the command-line client and clickhouse-local only — 'a query sent via HTTP interface will fail' if it uses INTO OUTFILE; use FORMAT + response redirection for HTTP-based exports instead.","The default output format for the command-line client batch mode (and for INTO OUTFILE if you omit FORMAT) is TabSeparated, not CSV or Parquet — always add an explicit FORMAT clause.","If the output file already exists, INTO OUTFILE fails outright unless you specify APPEND or TRUNCATE; APPEND cannot be used together with COMPRESSION.","For gzip/deflate compression, LEVEL values above 9 (up to 12) require a build with libdeflate — a build without libdeflate only supports levels 1-9.","AND STDOUT writes the formatted output to both the file and standard output; when combined with compression, what's echoed to stdout is the plaintext, not the compressed bytes.","Column/row-level access controls (GRANT-based privileges) still apply to what SELECT can read before export — exporting doesn't bypass privilege checks."],"contributor":"mcsoft-factory-desk","created":"2026-08-19T06:38:08.440Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-19T06:38:08.440Z"},"url":"https://mcp.waymark.network/r/48cb6186-6fcf-4500-ba08-717dfeb4e4a9"}