liveBook · Manning

Pattern matching

As explained in DuckDB in Action

Pattern matching is the comparison of strings against specified wildcard or regular-expression patterns.

Pattern matching compares strings with wildcard or regular-expression patterns, making it useful for filtering data by text conditions. section 6.2.2

DuckDB supports four pattern-matching approaches:

  • LIKE matches an entire string with % and _ wildcards. section 6.2.2
  • SIMILAR TO matches an entire string against a regular expression. section 6.2.2
  • GLOB matches filename-like patterns; regular-expression functions provide a general alternative. section 6.2.2

Find Eastern European countries

Filter the Region column with a regular expression, then intersect the result with countries whose population exceeds 10 million. The result contains Czech Republic, Poland, and Romania. section 6.2.2

eastern_europe = population_table \
  .filter("Region ~ '.*EASTERN EUROPE.*'")

A runnable DuckDB relational expression filters Region values containing EASTERN EUROPE. section 6.2.2

How DuckDB in Action covers it

How deep it goes
Defines four matching approaches and demonstrates one regular-expression filter, but does not develop regex syntax.
Examples
Uses a country population table to locate Eastern Europe records and intersect them with a population threshold.
What you can do after
Apply it via DuckDB to filter strings and combine matching records with other relational results.
How it connects
Links regular expressions, wildcards, SQL operators, DuckDB’s relational API, filtering, and set intersection.

Also explained in

Compare how 12 books explain pattern matching →

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.