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
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
| Flag | What it does |
|---|---|
| -c <sql> | Run one SQL statement and exit |
| -json | Emit results as a JSON array |
| -csv | Emit results as CSV |
| -line | One column per line output |
| -noheader | Omit 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.