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')"

Change the output format

Print results as markdown, CSV or JSON from the CLI.

.mode markdown

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');

Was this page helpful?