DuckDB 2 cheatsheet
DuckDB 2: Files and command line
6 common DuckDB 2 tasks.
Write query results to Parquet
Export a result as a compressed Parquet file.
COPY (SELECT * FROM sales) TO 'sales.parquet' (FORMAT parquet);
Write query results to CSV
Export a result as CSV with a header.
COPY (SELECT * FROM sales) TO 'sales.csv' (HEADER, DELIMITER ',');
Open a database in the CLI
Start the interactive shell on a database file. Omit the file for an in-memory database.
duckdb analytics.duckdb
Run a query from the shell
Run one statement and exit, which suits scripts.
duckdb -c "SELECT count(*) FROM read_parquet('data/*.parquet')"
Query files over HTTP or S3
Load the httpfs extension, then read remote files like local ones.
INSTALL httpfs;
LOAD httpfs;
SELECT count(*) FROM read_parquet('https://example.com/data.parquet');