# Replace values from a mapping table

Shape / columns

A variant of [Replace values](https://meridian.online/operations/replace-values).

Take the pairs of old and new values from a second table and apply them to one or more columns.

Page: <https://meridian.online/operations/replace-values/replace-values-from-a-mapping-table>

## Status

Runs as a SQL step.

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

## The DuckDB step

replace values with the pairs from a mapping table

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
CREATE TEMP TABLE mapping AS SELECT * FROM (VALUES
  ('north', 'N'), ('south', 'S'), ('east', 'E'), ('west', 'W'), ('widget', 'wdg'), ('gadget', 'gdg')
) t(old_value, new_value);
CREATE TEMP TABLE result AS
SELECT o.order_id, coalesce(mr.new_value, o.region) AS region, coalesce(mp.new_value, o.product) AS product
FROM orders o
LEFT JOIN mapping mr ON mr.old_value = o.region
LEFT JOIN mapping mp ON mp.old_value = o.product;
SELECT * FROM result ORDER BY order_id;
SELECT CASE WHEN ((SELECT count(*) FROM result) = 10 AND (SELECT list(DISTINCT region ORDER BY region) FROM result WHERE region IS NOT NULL) = ['E', 'N', 'S', 'W'] AND (SELECT count(*) FILTER (WHERE region IS NULL) FROM result) = 1 AND (SELECT list(DISTINCT product ORDER BY product) FROM result) = ['gdg', 'gizmo', 'wdg']) THEN 'as expected' ELSE error('region and product were not recoded from the mapping table, with unmapped values kept and ten rows out') 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).

- Alteryx Designer: [`Dynamic Replace`](https://help.alteryx.com/current/en/designer/tools/developer/dynamic-replace-tool.html) (read 2026-09-27)
- EasyMorph: [`Replace with lookup`](https://help.easymorph.com/doku.php?id=transformations:replacewithlookup) (read 2026-09-27)
- KNIME Analytics Platform: [`String Replacer (Dictionary)`](https://api.hub.knime.com/nodes/*yEWV69hLfijLvmTJ?details=full) (read 2026-09-27)
- Apache NiFi: [`ReplaceTextWithMapping`](https://nifi.apache.org/components/org.apache.nifi.processors.standard.ReplaceTextWithMapping/) (read 2026-09-27)
- Talend: [`tReplaceList`](https://help.qlik.com/talend/en-US/components/8.0/standardization/standardization-component) (read 2026-09-27)
