liveBook · Manning

Query builder

As explained in DuckDB in Action

A query builder is a programmatic interface that constructs database queries from composable operations rather than manually assembled query text.

A query builder constructs database queries by chaining composable operations such as filtering, projection, limiting, aggregation, ordering, and set operations. The resulting relational object remains reusable and acts like a table, view, or common table expression. section 6.2.2

(population_table
  .filter('Population > 10000000')  #1
  .project("Country, Population") #2
  .limit(5)
  .show()
)

Filter populations above ten million, select columns, limit the result, and execute the composed query with show(). section 6.2.2

Operations do not materialize intermediate results in the relational API, so their order does not affect performance. Execution is deferred until show() is called, while the builder can still accept operations such as offset or limit. section 6.2.2

Reuse a population filter

Define over_10m once, then aggregate average population by Region and order by the result. The same relation can also support filtering, counting, intersection, or exclusion. section 6.2.2

How DuckDB in Action covers it

How deep it goes
Explains chaining, deferred execution, reuse, aggregation, ordering, and set operations without descending into query-planner internals.
Examples
Uses population filtering, regional averages, counts, exclusions, regular-expression matching, and Eastern European intersections.
What you can do after
Apply it via DuckDB’s Python relational API to build, reuse, inspect, and extend lazy database queries.
How it connects
Connects filtering, projection, aggregation, lazy evaluation, pandas DataFrame materialization, and relational set operations.

Also explained in

Compare how 2 books explain query builder →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of DuckDB in Action. The section links point to the parts of the book it draws on.