Learn SQL
DuckDB Array Lambda Functions: list_transform, list_filter, and list_reduce Explained
DuckDB list lambdas let you map, filter, and reduce arrays inside SQL, creating compact pipelines for nested list data.
On This Page
Lists can be processed in place
Sometimes nested list data does not need to be unnested first. DuckDB list lambda functions let you transform, filter, and reduce list values directly inside a SELECT expression.
SQL for Files gives you a browser-based way to practice these DuckDB features on guided sample data or your own local files.
list_transform is the map operation
list_transform applies a lambda expression to every element and returns a new list with the transformed values.
SELECT customer, list_transform(prices, lambda p : p * 2) AS doubled_prices
FROM orders
ORDER BY customer;list_filter keeps matching elements
list_filter keeps only elements where the lambda returns true. If no elements qualify, the result is an empty list.
SELECT customer, list_filter(prices, lambda p : p > 10) AS high_prices
FROM orders
ORDER BY customer;list_reduce collapses a list into one value
list_reduce uses an accumulator to fold a list into one value, such as an order total. Combined with list_filter, it becomes a compact list-processing pipeline.
SELECT customer,
COALESCE(
list_reduce(
list_filter(prices, lambda p : p > 10),
lambda a, b : a + b
),
0
) AS expensive_total
FROM orders
ORDER BY customer;Practice the Array Lambdas chapter
- Use list_transform to apply a calculation to every price.
- Use list_filter to keep only prices above a threshold.
- Use list_reduce to calculate totals from list elements.
- Combine list functions into compact SQL pipelines.
Continue in the editor
Open SQL for Files to add your own CSV, JSON, or Parquet files and try these examples locally in your browser.
Open editorRelated guides
DuckDB SQL UNNEST Explained: Lists, Structs, Recursive Flattening, and max_depth
UNNEST is the bridge from nested data to queryable rows and columns, especially when working with JSON-like lists and structs.
How to Analyze JSON Files Locally with SQL
Load JSON or NDJSON into a local DuckDB table, then use SQL to inspect records, filter fields, and work with nested values.
What Is DuckDB WASM and Why Use It for Browser SQL?
DuckDB WASM brings an analytical SQL engine into the browser, enabling local file analysis without a server-side database.