100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

DuckDB Cheat Sheet

DuckDB Cheat Sheet

Run fast in-process analytical SQL queries directly on CSV, Parquet, and pandas data with DuckDB's embedded OLAP engine.

2 PagesBeginnerFeb 28, 2026

Query Files Directly with SQL

Run SQL over CSV and Parquet files without any loading step.

sql
-- query a CSV directlySELECT customer_id, SUM(amount) AS totalFROM 'orders.csv'GROUP BY customer_idORDER BY total DESCLIMIT 10;-- query multiple partitioned parquet files with a globSELECT status, COUNT(*) FROM 'data/orders/*.parquet' GROUP BY status;

Embedded in Python

Use DuckDB as an in-process analytical engine directly against pandas or Polars data.

python
import duckdbimport pandas as pddf = pd.read_csv("orders.csv")# DuckDB can query a pandas DataFrame by variable name, no import stepresult = duckdb.sql("SELECT status, AVG(amount) FROM df GROUP BY status").df()# or via a persistent connectioncon = duckdb.connect("analytics.duckdb")con.execute("CREATE TABLE orders AS SELECT * FROM df")

Read from S3 with httpfs

Install the httpfs extension and query remote object storage directly.

sql
INSTALL httpfs;LOAD httpfs;SET s3_region='us-east-1';SET s3_access_key_id='...';SET s3_secret_access_key='...';SELECT * FROM read_parquet('s3://my-bucket/events/*.parquet') LIMIT 100;

Export Query Results

Write query output to Parquet or CSV using the COPY statement.

sql
COPY (  SELECT customer_id, SUM(amount) AS total  FROM orders  GROUP BY customer_id) TO 'summary.parquet' (FORMAT PARQUET);COPY orders TO 'orders.csv' (HEADER, DELIMITER ',');

CLI Essentials

Common ways to start and use the DuckDB command-line shell.

  • duckdb- launches an in-memory database shell
  • duckdb mydb.duckdb- opens or creates a persistent on-disk database file
  • .mode csv / .mode markdown- changes the shell's output format
  • .import file.csv table- loads a CSV into a table from the shell
  • EXPLAIN ANALYZE <query>- shows the physical query plan with timings
Pro Tip

Reach for duckdb.sql("... FROM df ...") instead of pandas groupby chains on anything over a few million rows — DuckDB's vectorized engine will usually finish in a fraction of the time with far less peak memory.

Was this cheat sheet helpful?

Explore Topics

#DuckDB#DuckDBCheatSheet#DataScience#Beginner#Query#Files#Directly#SQL#Databases#MachineLearning#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet