Using LIST_REVERSE() to Reverse the Items in a List in DuckDB

Deep amongst DuckDB’s vast selection of list functions lies the list_reverse() function. This function reverses the elements in a list. We simply pass the list to the function and it reverses the order of the elements in that list.

Not to be confused with the list_sort() or list_reverse_sort() functions, the list_reverse() function reverses the order of the items as they currently sit in the list. The ...sort() functions on the other hand, actually perform a sort operation on the list items.

Continue reading

Unnesting Lists & Structs with DuckDB’s UNNEST() Function

DuckDB has an unnest() function that we can use to unnest lists and structs. Well, it can also be applied to NULL, but that’ll return an empty result.

By “unnest” I mean it takes the list or struct, and it returns its contents as rows in a table. You might say that it converts lists and structs into tables, where each item in the list or struct becomes a row in the table.

Below are examples of using DuckDB’s unnest() function to unnest lists and structs.

Continue reading

Check if a Sub-List Appears in a Larger List in DuckDB: LIST_HAS_ALL()

When working with lists in DuckDB, we sometimes need to check whether a list contains specific elements. The list_has_all() function is a handy tool that allows us to verify if all elements of one list exist within another. This function is particularly useful in filtering queries, data validation, and advanced list-based operations.

In this article, we’ll explore how list_has_all() works in DuckDB.

Continue reading