liveBook · Manning

List_contains

As explained in DuckDB in Action

list_contains is a DuckDB function that tests whether a list contains a specified value.

list_contains tests whether a list contains a specified value. In a posts table, it replaces substring matching when tags are stored as a list, making membership explicit and usable in SQL filters. section 10.1.7

Count posts carrying a tag

SELECT count(*) FROM posts WHERE postTypeId = 1 AND list_contains(tagNames, 'java'); The same predicate works with an enum list: list_contains(tagEnums, 'java'). On 28 million rows, the string-list operation runs in 0.24 seconds; the enum-list version runs in 0.17 seconds. section 10.1.7

How DuckDB in Action covers it

How deep it goes
Defines membership filtering and compares string-list and enum-list runtimes, without detailing function internals.
Examples
Demonstrates counting Java-tagged posts using VARCHAR[] and ENUM[] columns.
What it assumes
Assumes SQL filtering and list-valued columns, while the examples establish tag-list preparation and enum conversion.
What you can do after
Apply it via DuckDB SQL to filter list-valued rows and compare string-list and enum-list representations.
How it connects
Connects list_contains with LIST, ENUM, list_transform, and SQL filtering.

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.