# Detect a CSV file's settings

Acquire / file

A variant of [Read a CSV or delimited file](https://meridian.online/operations/read-a-csv-or-delimited-file).

Read the start of a CSV file and report the delimiter, quoting, header and column types it uses.

Page: <https://meridian.online/operations/read-a-csv-or-delimited-file/detect-a-csv-files-settings>

## Status

Runs as a SQL step.

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

## The DuckDB step

report the delimiter, quoting, header and column types of two files

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
COPY (SELECT order_id, customer, order_date, amount FROM orders) TO '<your_scratch_dir>/semi.csv' (DELIMITER ';', QUOTE '"', FORCE_QUOTE (customer), HEADER);
COPY (SELECT * FROM (VALUES (1, DATE '2026-01-03', 2.5), (2, DATE '2026-01-04', 3.5), (3, DATE '2026-01-05', 4.5)) t(a, b, c))
  TO '<your_scratch_dir>/tabbed.csv' (DELIMITER '\t', HEADER false);
CREATE TEMP TABLE result AS
SELECT 'semi' AS file, Delimiter AS delim, Quote AS quote, HasHeader AS has_header, list_transform(Columns, lambda c: c.name) AS names, list_transform(Columns, lambda c: c.type) AS types FROM sniff_csv('<your_scratch_dir>/semi.csv')
UNION ALL
SELECT 'tabbed', Delimiter, Quote, HasHeader, list_transform(Columns, lambda c: c.name), list_transform(Columns, lambda c: c.type) FROM sniff_csv('<your_scratch_dir>/tabbed.csv');
SELECT * FROM result ORDER BY file;
SELECT CASE WHEN ((SELECT count(*) FROM result) = 2 AND (SELECT delim = ';' AND quote = '"' AND has_header AND names = ['order_id', 'customer', 'order_date', 'amount'] AND types = ['BIGINT', 'VARCHAR', 'DATE', 'DOUBLE'] FROM result WHERE file = 'semi') AND (SELECT delim = '	' AND NOT has_header AND types = ['BIGINT', 'DATE', 'DOUBLE'] FROM result WHERE file = 'tabbed')) THEN 'as expected' ELSE error('sniffing did not report one row per file with the semicolon file delimiter, quote, header and types and the tab file lack of a header') 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 `semi.csv` and `tabbed.csv` itself, in `<your_scratch_dir>`.

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).

- DuckDB: `sniff_csv` (read 2026-09-27)
