Introduction
Why DuckDB rocks
In this book one SQL engine with no server counted 4.4 billion taxi rows from file footers, read 85 GB of Wikipedia clickstream on a 16 GB machine and rebuilt a state's liquor ledger on a laptop. This page says what makes that possible, what DuckDB 2.0 added, and where the engine fell short.
On this page
- It runs inside your program, so there is nothing to stand up
- It reads files where they live and fetches only what a query needs
- It is built for scans and aggregates, and it spills to disk when memory runs out
- Its SQL is meant to be typed by people
- Extensions bring the rest of the toolkit to the same engine
- What 2.0 changed
- Where DuckDB was the weak link
- How to use the rest of the book
Every result in this book came from one program that needs no server and no cluster, and that can query files where they sit before anything is loaded; chapters materialize a table only when the workflow gains from it, as the liquor ledger does. On ordinary machines, often with two threads and a 2.5 GB memory cap, DuckDB counted 4.40 billion New York taxi rows from the footers of 594 files without downloading the trips, read 84.66 GB of Wikipedia clickstream on a 16 GB machine, and rebuilt a state wholesaler's books from 8.4 GB of zipped invoices on a laptop. The table below lists those runs. The rest of this page explains which design choices made them cheap, what the 2.0 release changed, and where DuckDB was the weak link.
The book's larger sources ran on a laptop or a few small cloud tasks
| 1 | NYC TLC trip records, Parquet over HTTPS | 594 files, 81.3 GB, 4.40 billion rows | Footers of every file; full columns only for the April files | 4-core, 15 GB cloud container | 49.0 s for the footer inventory of every file |
| 2 | Amazon Reviews 2023, JSONL on Hugging Face | 34 files, about 280 GB, 571.54 million reviews | Every review, downloaded in 1 GB chunks | 8 cloud tasks × 4 vCPU, 16 GiB | 8 min 9 s, $0.43 |
| 3 | Wikimedia clickstream, monthly TSV.gz | 742 files, 84.66 GB compressed, 6.38 billion rows | Every file once, three at a time, 2 threads and 3 GB each | 4-core, 16 GB cloud sandbox | 35 min 40 s |
| 4 | Open Food Facts, one Parquet file on Hugging Face | 111 columns, world catalog | 17 columns, US rows only | 4-core, 16 GB container; threads = 2, memory_limit = 2.5 GB | 844 s for the whole pipeline |
| 6 | FEC individual contributions, zipped text | 10 election cycles, 53 GB, 279.6 million rows | Every row; a Python step unzips and hands DuckDB 1 GB chunks | 10 cloud tasks × 4 vCPU, 16 GiB | $0.26 for the cloud run |
| 7 | Overture Maps places, GeoParquet on S3 | 11.82 GB release | 2.97 GB: 1,821 of 6,144 row groups | Windows desktop; threads = 2, memory_limit = 2.5 GB | 376 s for the whole pipeline |
| 10 | Iowa liquor invoices, zipped CSV | 15 yearly exports, 8.4 GB | 66 CSV parts read inside the zips | Windows laptop | about 110 s to load, 15 s to model |
| 12 | SEC financial statement extracts | 1.3 GB of quarterly zips | Every filing's tagged values | Windows laptop | about 10 s for the whole pipeline |
pipeline/README.md. Times include network transfer and differ between machines and runs; they show the order of magnitude, not a benchmark. Chapter numbers are reading order.SourceChapter run logs, 2026-10-24 to 2026-12-03, DuckDB 2.0.0None of these needed a database administrator, a schema created in advance or a copy of the source held locally before the first query. That is the case for DuckDB in one sentence, and the sections below take it apart.
It runs inside your program, so there is nothing to stand up
DuckDB is a library. The CLI is one executable; in Python it is pip install duckdb; in R, Node, Go, Java and Rust it is a package that links the same engine. It has no external dependencies at build time or run time, and it is released under the MIT License, with the intellectual property held by the non-profit DuckDB Foundation (Why DuckDB). It started as a research system at CWI in Amsterdam, presented as "an embeddable analytical database" at SIGMOD in 2019 (Raasveldt and Mühleisen, 2019).
The practical effect shows up in Chapter 0: install, build a list of URLs in SQL, count rows, check the count against the publisher's own figure, and save the two statements in a file that reruns. A database lives in a single file, or in no file at all, and a query result can be written to Parquet, CSV or JSON with one COPY. That is why every chapter can ship a run.sh that a reader runs on their own machine.
It reads files where they live and fetches only what a query needs
Most chapters never load their source. DuckDB queries Parquet, CSV and JSON files on local disk, over HTTPS, on S3 or on Hugging Face as if they were tables, and Parquet files carry enough metadata that it can skip what a query does not touch. Chapter 1 measured this on one month of yellow-cab trips with HTTP logging on:
Naming one column downloads a small fraction of a remote Parquet file
| count(*) only | 1 | 65.5K | 3831240 |
| one column | 5 | 5.4M | 5.18 |
| one column + filter on pickup time | 5 | 10.2M | 4.754 |
| every column | 5 | 64.9M | 1842120001 |
count(*) cost 64 KB, because the row count sits in the file's footer. One column cost 5.4 MB and the whole file 64.9 MB. The same property let Chapter 4 pull 17 of Open Food Facts' 111 columns, US rows only, in one remote read, and let Chapter 7 read 2.97 GB of Overture's 11.82 GB places release, the row groups that fall inside the United States.
The formats go beyond Parquet. Chapter 11 reads an Excel workbook sheet by sheet with read_xlsx; Chapter 10 reads CSV files inside zip archives with the zipfs extension, so nothing is unpacked to disk; Chapter 2 reads JSON lines. And because Chapter 1's seventeen years of taxi files use 67 distinct column names, union_by_name = true lines the files up by name and fills the gaps with NULL, which turns a schema-reconciliation project into one query option.
It is built for scans and aggregates, and it spills to disk when memory runs out
Analytical questions read many rows and few columns, then group and join. DuckDB stores and processes data by column and runs each operator over a batch ("vector") of values at once, rather than row by row as SQLite, PostgreSQL and MySQL do (Why DuckDB). It uses every core by default. When a join or aggregate does not fit in memory, it writes the overflow to a temporary directory and keeps going.
That last property is what most of this book leans on. Pipelines here set threads = 2 and memory_limit = '2.5GB' so several can share one machine, and still finish. Chapter 3 staged 6.38 billion clickstream rows three files at a time on a 4-core, 16 GB sandbox. At the other extreme, DuckDB Labs ran all 22 TPC-H queries at scale factor 100,000 (about 100 TB of CSV) on one large server, with some queries spilling about 7 TB to disk (DuckDB blog, October 2025). The same post reports DuckDB as the fastest open-source system on hot runs of the ClickBench benchmark at the time; such rankings move, so treat them as a sign of the engine's class rather than a fixed fact.
Its SQL is meant to be typed by people
DuckDB accepts standard SQL and adds conveniences that remove boilerplate: FROM table with no SELECT, GROUP BY ALL, SELECT * EXCLUDE (…), SUMMARIZE for a quick profile of every column, list and struct types with Python-style lambdas, and, since 2.0, $name variables. This query, adapted from the first one in Chapter 0, builds three months of URLs and counts trips per file without leaving SQL:
SET VARIABLE urls = list_transform(range(1, 4), lambda m:
printf('https://d37ci6vzurychx.cloudfront.net/trip-data/yellow_tripdata_2024-%02d.parquet', m));
SELECT filename, count(*) AS trips
FROM read_parquet($urls, filename = true)
GROUP BY ALL ORDER BY filename;Because the pipelines are SQL files, a reader can open chapters/<nn>-<slug>/pipeline/ and follow each step, and the same text runs unchanged in the CLI, in Python and in R.
Extensions bring the rest of the toolkit to the same engine
Parquet, JSON, HTTP and S3 access are themselves extensions, and others add whole domains (Why DuckDB). In this book:
- Spatial. Chapter 7 finds the nearest supermarket and dollar store for every populated census tract in the lower 48 with an R-tree spatial join in 2.7 s, and checks it against H3 cells from the community
h3extension. - Vectors. Chapter 5 stores text embeddings as fixed-size arrays, retrieves store-brand candidates by cosine similarity with a
NEARESTjoin, and in its Lab section compares that with brute force and with an HNSW index from thevssextension. - Lakehouse tables. Chapter 14 keeps two monthly Overture releases as DuckLake snapshots, so a later reader can query the exact rows an earlier answer used.
- Workbooks and archives.
excelandzipfsabove, in Chapters 11 and 10.
Chapter 13 uses no special extension at all: it stores a model's answers and probabilities as versioned rows, which is enough to rank, threshold and audit them with ordinary SQL.
What 2.0 changed
The book was built on the 2.0 long-term-support release (announcement). Its main additions:
- A server when you want one. The Quack protocol and a
CONNECTstatement let one DuckDB serve others, and the CLI gains-serveand-connect. Several processes writing to one database file go through Quack, or through a DuckLake catalog on PostgreSQL (concurrency docs). The embedded mode this book uses is unchanged. - Faster remote reads. Asynchronous I/O keeps several requests in flight for Parquet, CSV and native files, which matters most on object storage.
VARIANT. A typed, automatically shredded alternative to JSON for semi-structured data.- New SQL.
NEARESTjoins, triggers, data-modifying CTEs, nested schemas and$variables, on a new PEG parser that extensions can add grammar to. - Agent mode. When an AI agent drives the CLI, output switches to compact Markdown with truncation markers and JSON errors; the release post reports 59% less output for a model to read in its TPC-H experiments. Each chapter's manifest records a result hash for every output.
- Lakehouse formats. DuckLake 1.1;
CREATE TABLEand time travel in the Delta extension; more catalog options for Iceberg.
Upgrading has costs. Files written by 2.0 cannot be opened by 1.x; single-arrow lambdas (x -> x + 1) are off by default and every query here uses lambda x: x + 1; and 2.0.1 reverted a change to MERGE and UPDATE … FROM with several matching rows, with a fix promised for 2.1 (2.0.1 announcement). The migration guide lists the rest.
Where DuckDB was the weak link
The chapters record the places DuckDB itself cost time, and they are as useful as the speed-ups:
None of these changed a result, because each chapter checks its counts against a known value before it reports them. That habit, more than any engine, is what the rest of the book teaches; DuckDB makes it cheap enough to do every time.
How to use the rest of the book
Start with Chapter 0 to install 2.0.0 and test the sources. Then read for the question that interests you, or go by technique: Chapter 1 for remote Parquet and schema drift, Chapter 3 for a resumable scan of hundreds of files, Chapter 7 for spatial joins, Chapter 5 for similarity search, Chapters 10 to 13 for business workflows on files an analyst inherits, and Chapter 14 for answers that must survive the next data release.