Skip to content
Latchkey

DuckDB CLI: Query CSV, JSON and Parquet In Place

The DuckDB CLI can query CSV, JSON, and Parquet files as if they were tables using read_csv, read_json, and read_parquet, without any import step.

DuckDB is an embedded analytical database, but for CI its killer feature is querying files in place. You pass -c with a SELECT that names the file, and it streams the answer, no schema setup required. This page focuses on file querying; the general shell is covered under duckdb-command.

What it does

The duckdb CLI executes SQL where file-reading table functions stand in for tables: read_csv_auto('f.csv'), read_json_auto('f.json'), read_parquet('f.parquet'). It infers types, handles compression, and can output JSON or a table.

Common usage

Terminal
duckdb -c "SELECT count(*) FROM read_csv_auto('report.csv')"
duckdb -json -c "SELECT name FROM read_json_auto('users.json') WHERE age > 30"
# aggregate straight over Parquet
duckdb -c "SELECT status, count(*) FROM read_parquet('events.parquet') GROUP BY status"

Options

FlagWhat it does
-c <sql>Run one SQL statement and exit
-jsonEmit results as a JSON array
-csvEmit results as CSV
-lineOne column per line output
-noheaderOmit the header row

In CI

For gating on data, duckdb -c "SELECT count(*) FROM read_csv_auto('x.csv') WHERE ..." returns a single value you can test. read_csv_auto sniffs the delimiter and types; if it guesses wrong, use read_csv with explicit columns or delim. Parquet querying is far faster than converting to CSV first.

Common errors in CI

"IO Error: No files found that match the pattern" means a wrong path or glob. "Invalid Input Error: Could not convert string ... to ..." is a type-inference miss; set sample_size or explicit column types in read_csv. "Binder Error: Referenced column ... not found" means a wrong column name, often a header mismatch. Missing Parquet support prints a loader error; ensure the parquet extension is available.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →