# Promote a row to headers

Shape / columns

promote a row to headers, or demote headers to a row

Page: <https://meridian.online/operations/promote-a-row-to-headers>

## Status

Runs as a SQL step.

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

## The DuckDB step

promote the second line of a file to headers

```sql
COPY (SELECT 'exported 2026-09-27' AS line UNION ALL SELECT 'id,name' UNION ALL SELECT '1,a' UNION ALL SELECT '2,b') TO '<your_scratch_dir>/preamble.csv' (HEADER false, QUOTE '');
CREATE TEMP TABLE result AS
SELECT * FROM read_csv('<your_scratch_dir>/preamble.csv', skip = 1, header = true);
SELECT * FROM result;
SELECT CASE WHEN ((SELECT list(column_name) = ['id', 'name'] FROM (DESCRIBE result)) AND (SELECT count(*) = 2 AND list(name ORDER BY id) = ['a', 'b'] FROM result)) THEN 'as expected' ELSE error('the second line did not become the column names') END AS verdict;
```

Replace `<your_scratch_dir>` with a directory of your own that you can write to before running the statement.

The statement writes `preamble.csv` itself, in `<your_scratch_dir>`.

It needs nothing installed beyond DuckDB itself.

## Variants

- [Demote headers to a row](https://meridian.online/operations/promote-a-row-to-headers/demote-headers-to-a-row): Move the column names into a new first data row and give the columns default names.
- Use the first row as headers: Take the column names from the first data row and remove that row.

## What other tools call it

Meridian's classification; an independent blind rating agreed on 86.2% of 312 rows (exact class, version 2).

- Power Query M: [`Table.DemoteHeaders`](https://learn.microsoft.com/en-us/powerquery-m/table-functions#column-operations) (read 2026-09-27)
- Power Query M: [`Table.PromoteHeaders`](https://learn.microsoft.com/en-us/powerquery-m/table-functions#column-operations) (read 2026-09-27)
