Learn SQL Lesson
Unnesting Structs into Columns
When a column holds a `STRUCT`, `UNNEST` expands its fields into separate columns.
If the contacts table has an `address` column of type `STRUCT(city VARCHAR, zip VARCHAR)`:
SELECT name, unnest(address)
FROM contacts
This produces columns `name`, `city`, and `zip` — one column per struct field.
Note the difference from list unnesting: lists expand vertically (more rows), while structs expand horizontally (more columns). The row count stays the same.
This is especially useful when importing JSON data where objects are stored as DuckDB structs.
Practice challenge
Unnest the address struct so city and zip become their own columns. Return name, city, and zip, ordered by name.