# Insert rows

Shape / rows

A variant of [Edit cells by hand](https://meridian.online/operations/edit-cells-by-hand).

Add blank, constant or supplied rows at a chosen position.

Page: <https://meridian.online/operations/edit-cells-by-hand/insert-rows>

## Status

Runs as a SQL step.

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

## The DuckDB step

insert blank, constant and supplied rows at chosen positions

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 numbered AS
SELECT row_number() OVER (ORDER BY order_id) AS pos, order_id, customer, amount FROM orders;
-- each patch row says which position it follows; rows that follow the same position keep their `seq` order
CREATE TEMP TABLE patch AS SELECT * FROM (VALUES
  (2, 1, NULL::INTEGER, NULL::VARCHAR, NULL::DECIMAL(5, 2)),   -- a blank row after row 2
  (5, 1, 0,             'Subtotal',    0.00),                  -- a constant row after row 5
  (8, 1, 101,           'Gus Hall',    12.00),                 -- supplied rows after row 8
  (8, 2, 102,           'Hana Iyer',   34.00)
) t(after_pos, seq, order_id, customer, amount);
CREATE TEMP TABLE result AS
SELECT row_number() OVER (ORDER BY place, seq) AS pos, order_id, customer, amount
FROM (SELECT pos AS place, 0 AS seq, order_id, customer, amount FROM numbered
      UNION ALL
      SELECT after_pos + 0.5, seq, order_id, customer, amount FROM patch);
SELECT * FROM result ORDER BY pos;
SELECT CASE WHEN ((SELECT count(*) FROM result) = 14 AND (SELECT list(order_id ORDER BY pos) FROM result) IS NOT DISTINCT FROM [1, 2, NULL, 3, 4, 5, 0, 6, 7, 8, 101, 102, 9, 10] AND (SELECT customer FROM result WHERE pos = 3) IS NULL AND (SELECT customer FROM result WHERE pos = 7) = 'Subtotal' AND (SELECT list(customer ORDER BY pos) FROM result WHERE pos IN (11, 12)) = ['Gus Hall', 'Hana Iyer']) THEN 'as expected' ELSE error('the result was not the ten orders with a blank row at 3, a Subtotal row at 7 and two supplied rows at 11 and 12') 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).

- KNIME Analytics Platform: [`Constant Value Row Appender`](https://api.hub.knime.com/nodes/*k4Q1HIlGwZupSTmt?details=full) (read 2026-09-27)
- OpenRefine: [`Add blank rows`](https://github.com/OpenRefine/OpenRefine/blob/master/main/webapp/modules/core/scripts/views/data-table/data-table-view.js) (read 2026-09-27)
- Power Query M: [`Table.InsertRows`](https://learn.microsoft.com/en-us/powerquery-m/table-functions#row-operations) (read 2026-09-27)
- VisiData: [`add-row`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/modify.py#L357) (read 2026-09-23)
- VisiData: [`add-rows`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/modify.py#L358) (read 2026-09-23)
