# Keep rows that contain text

Shape / rows

A variant of [Filter rows](https://meridian.online/operations/filter-rows).

Keep or drop the rows whose cells contain a string or match a pattern, in one column or any.

Page: <https://meridian.online/operations/filter-rows/keep-rows-containing-text>

## Status

Runs as a SQL step.

arcform carries it as a `sql:` step today.

## The DuckDB step

keep or drop rows that contain a string or match a pattern, in one column or any

It reads the `orders` table the proofs share. Create it first:

```sql
CREATE TABLE orders AS SELECT * FROM (VALUES
  (1,  'Alice Ng',      'north', DATE '2026-01-03', 120.00, 'widget', 'a|b',   '{"channel":"web","items":[1,2]}'),
  (2,  'alice ng',      'north', DATE '2026-01-05',  80.50, 'gadget', 'b',     '{"channel":"shop","items":[3]}'),
  (3,  'Bob  Okafor',   'south', DATE '2026-01-05', 300.00, 'widget', 'a|c',   '{"channel":"web","items":[4,5,6]}'),
  (4,  'Carla Díaz',    'east',  DATE '2026-01-09',  NULL,  'gizmo',  NULL,    '{"channel":"web","items":[]}'),
  (5,  'Bob Okafor',    'south', DATE '2026-01-12',  45.25, 'gadget', 'c',     '{"channel":"phone","items":[7]}'),
  (6,  'Dev Patel',     'west',  DATE '2026-01-12', 510.00, 'widget', 'a',     '{"channel":"web","items":[8,9]}'),
  (7,  'Carla Diaz',    'east',  DATE '2026-01-20',  99.99, 'gizmo',  'b|c',   '{"channel":"shop","items":[10]}'),
  (8,  'Dev Patel',     'west',  DATE '2026-02-02', 510.00, 'widget', 'a',     '{"channel":"web","items":[8,9]}'),
  (9,  'Eve Larsen',    NULL,    DATE '2026-02-03',  15.00, 'gadget', NULL,    '{"channel":"web","items":[11]}'),
  (10, 'Alice Ng',      'north', DATE '2026-02-10', 220.00, 'gizmo',  'a|b|c', '{"channel":"phone","items":[12,13]}')
) t(order_id, customer, region, order_date, amount, product, tags, meta);
```

Then run the statement:

```sql
-- one column, a string (case-insensitive)
CREATE TEMP TABLE has_string AS SELECT order_id FROM orders WHERE contains(lower(customer), 'alice');
-- one column, a pattern
CREATE TEMP TABLE has_pattern AS SELECT order_id FROM orders WHERE regexp_matches(customer, '^(Dev|Eve) ');
-- the rows that do not contain the string
CREATE TEMP TABLE lacks_string AS SELECT order_id FROM orders WHERE NOT contains(lower(customer), 'alice');
-- any text column
CREATE TEMP TABLE in_any_column AS
SELECT order_id FROM orders
WHERE customer ILIKE '%phone%' OR region ILIKE '%phone%' OR product ILIKE '%phone%' OR tags ILIKE '%phone%' OR meta ILIKE '%phone%';
-- the same word in the customer column alone finds nothing, so any column differs from one
CREATE TEMP TABLE in_customer_only AS SELECT order_id FROM orders WHERE customer ILIKE '%phone%';
SELECT list(order_id ORDER BY order_id) AS has_string FROM has_string;
SELECT list(order_id ORDER BY order_id) AS in_any_column FROM in_any_column;
SELECT CASE WHEN ((SELECT list(order_id ORDER BY order_id) FROM has_string) = [1, 2, 10] AND (SELECT list(order_id ORDER BY order_id) FROM has_pattern) = [6, 8, 9] AND (SELECT count(*) FROM lacks_string) = 7 AND (SELECT list(order_id ORDER BY order_id) FROM in_any_column) = [5, 10] AND (SELECT count(*) FROM in_customer_only) = 0) THEN 'as expected' ELSE error('the string, the pattern, the exclusion or the any-column match did not return the expected orders') END AS verdict;
```

It needs nothing installed beyond DuckDB itself.

## What other tools call it

Meridian's classification; an independent blind rating agreed on 95.7% of 324 rows (variant, version 3).

- EasyMorph: [`Filter by search`](https://help.easymorph.com/doku.php?id=transformations:searchfilter) (read 2026-09-27)
- Apache NiFi: [`Filter Functions`](https://nifi.apache.org/nifi-docs/record-path-guide.html) (read 2026-09-27)
- OpenRefine: [`Text filter`](https://openrefine.org/docs/manual/facets#text-filter) (read 2026-09-27)
- Power Query M: [`Table.FindText`](https://learn.microsoft.com/en-us/powerquery-m/table-functions#row-operations) (read 2026-09-27)
- Tableau Prep: [`Wildcard Match`](https://help.tableau.com/current/prep/en-us/prep_filter.htm) (read 2026-09-27)
- Trifacta: [`Filter contains`](https://help.alteryx.com/aac/en/trifacta-classic/reference/transformation-reference.html) (read 2026-09-27)
- Trifacta: [`Filter ends with`](https://help.alteryx.com/aac/en/trifacta-classic/reference/transformation-reference.html) (read 2026-09-27)
- Trifacta: [`Filter starts with`](https://help.alteryx.com/aac/en/trifacta-classic/reference/transformation-reference.html) (read 2026-09-27)
- VisiData: [`dup-search`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/experimental/live_search.py#L36) (read 2026-09-23)
- VisiData: [`dup-search-cols`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/experimental/live_search.py#L37) (read 2026-09-23)
