# Work with map values

Shape / columns

A variant of [Parse nested values](https://meridian.online/operations/parse-nested-values).

Build maps, look up a key, list keys or values, and merge maps.

Page: <https://meridian.online/operations/parse-nested-values/work-with-map-values>

## Status

Runs as a SQL step.

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

## The DuckDB step

build a map, look up a key, list its keys and values and merge two maps

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 result AS
SELECT order_id,
       map_from_entries([('customer', customer), ('region', region)]) AS m,
       m['region'] AS region_lookup,
       m['missing'] AS missing_lookup,
       map_keys(m) AS keys,
       map_values(m) AS vals,
       map_concat(m, MAP {'region': 'unknown', 'source': 'import'}) AS merged
FROM orders;
SELECT * FROM result ORDER BY order_id;
SELECT CASE WHEN ((SELECT [region_lookup, missing_lookup] FROM result WHERE order_id = 1) = ['north', NULL] AND (SELECT keys FROM result WHERE order_id = 1) = ['customer', 'region'] AND (SELECT vals FROM result WHERE order_id = 1) = ['Alice Ng', 'north'] AND (SELECT merged FROM result WHERE order_id = 1) = MAP {'customer': 'Alice Ng', 'region': 'unknown', 'source': 'import'} AND (SELECT region_lookup FROM result WHERE order_id = 9) IS NULL AND (SELECT merged['region'] FROM result WHERE order_id = 9) = 'unknown') THEN 'as expected' ELSE error('the map did not give its keys, values and a looked-up key, or the merge did not let the second map override the first') 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).

- Azure Data Factory: [`Map functions`](https://learn.microsoft.com/en-us/azure/data-factory/data-flow-map-functions) (read 2026-09-27)
- Apache DataFusion: [`Map Functions`](https://datafusion.apache.org/user-guide/sql/scalar_functions.html) (read 2026-09-27)
- DuckDB: [`Map Functions (family)`](https://duckdb.org/docs/current/sql/functions/map) (read 2026-09-27)
- Ibis: [`Map`](https://github.com/ibis-project/ibis/blob/05d2b293344e86cb41c1a426071734f7e270335a/ibis/expr/operations/maps.py) (read 2026-09-27)
- Ibis: [`MapContains`](https://github.com/ibis-project/ibis/blob/05d2b293344e86cb41c1a426071734f7e270335a/ibis/expr/operations/maps.py) (read 2026-09-27)
- Ibis: [`MapGet`](https://github.com/ibis-project/ibis/blob/05d2b293344e86cb41c1a426071734f7e270335a/ibis/expr/operations/maps.py) (read 2026-09-27)
- Ibis: [`MapKeys`](https://github.com/ibis-project/ibis/blob/05d2b293344e86cb41c1a426071734f7e270335a/ibis/expr/operations/maps.py) (read 2026-09-27)
- Ibis: [`MapLength`](https://github.com/ibis-project/ibis/blob/05d2b293344e86cb41c1a426071734f7e270335a/ibis/expr/operations/maps.py) (read 2026-09-27)
- Ibis: [`MapMerge`](https://github.com/ibis-project/ibis/blob/05d2b293344e86cb41c1a426071734f7e270335a/ibis/expr/operations/maps.py) (read 2026-09-27)
- Ibis: [`MapValues`](https://github.com/ibis-project/ibis/blob/05d2b293344e86cb41c1a426071734f7e270335a/ibis/expr/operations/maps.py) (read 2026-09-27)
