liveBook · Manning

List_transform

As explained in DuckDB in Action

list_transform is a DuckDB list function that applies a lambda function to each element of a list and returns the transformed list.

list_transform applies a lambda to every element of a DuckDB list and returns a transformed list. It is useful when converting tag strings into normalized or enum-valued entries. section 10.1.7

Convert tag names into enum values

UPDATE posts SET tagEnums = list_transform(tagNames, x -> upper(x)::tag) WHERE posttypeid = 1; Each tagNames element is uppercased and cast to the tag enum before the resulting list is stored in tagEnums.

How DuckDB in Action covers it

How deep it goes
Demonstrates elementwise lambda application with uppercasing and enum casting, without detailing lambda internals.
Examples
Uses tagNames, tagEnums, uppercase tag values, and enum casts in an UPDATE statement.
What it assumes
Assumes familiarity with DuckDB lists, enum types, UPDATE statements, and lambda expressions.
What you can do after
Apply it via DuckDB SQL to normalize or cast every value in a list.
How it connects
Connects lists, lambda functions, enum types, list_contains, and unnest.

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.