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 · 8 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. 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
  2. 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]].
  3. 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.
  4. 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).
  5. 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.
  6. 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').
  7. If the target output file already exists, the query fails unless you add APPEND or TRUNCATE (APPEND cannot be combined with COMPRESSION).
  8. Reference: https://clickhouse.com/docs/sql-reference/statements/select/into-outfile

Known gotchas

Related routes

Query local and remote files (CSV, TSV, Parquet, JSON, etc.) with SQL using clickhouse-local, without running a ClickHouse server, relying on schema inference or explicit format hints.
clickhouse.com · 8 steps · unrated
Connect to ClickHouse from Python with clickhouse-connect and run queries, DDL commands, and inserts, including against ClickHouse Cloud.
clickhouse.com · 8 steps · unrated

Give your agent this knowledge — and 17,900+ more routes

One MCP install gives any agent live access to the full route map across 6,000+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans