# Write a CSV or delimited file

Publish / file

write CSV, TSV, fixed-width

Page: <https://meridian.online/operations/write-a-csv-or-delimited-file>

## Status

Runs as a SQL step.

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

## The DuckDB step

write CSV

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 * FROM orders) TO '<your_scratch_dir>/out.csv' (HEADER, DELIMITER ',');
CREATE TEMP TABLE result AS
SELECT count(*) AS n, sum(amount) AS total FROM read_csv('<your_scratch_dir>/out.csv');
SELECT * FROM result;
SELECT CASE WHEN ((SELECT n = 10 AND total = 1900.74 FROM result)) THEN 'as expected' ELSE error('the CSV written does not read back as 10 rows totalling 1900.74') 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 `out.csv` itself, in `<your_scratch_dir>`.

It needs nothing installed beyond DuckDB itself.

## Variants

- Write a delimited text file: Write rows as text with a separator between fields, such as commas, tabs or pipes.
- Write a fixed-width file: Write rows as text where each field takes a set number of characters, padded to its width.

## What other tools call it

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

- Azure Data Factory: [`Delimited text format (sink)`](https://learn.microsoft.com/en-us/azure/data-factory/format-delimited-text) (read 2026-09-27)
- Apache DataFusion: [`Data Insert: CSV`](https://datafusion.apache.org/user-guide/features.html) (read 2026-09-27)
- Apache DataFusion: [`write_csv`](https://docs.rs/datafusion/latest/datafusion/dataframe/struct.DataFrame.html) (read 2026-09-27)
- Duckle: [`CSV`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/website/docs/components.html) (read 2026-09-25)
- Duckle: [`TSV`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/website/docs/components.html) (read 2026-09-25)
- EasyMorph: [`Export into delimited text file`](https://help.easymorph.com/doku.php?id=transformations:exporttext) (read 2026-09-27)
- AWS Glue: [`CSV (write)`](https://docs.aws.amazon.com/glue/latest/dg/aws-glue-programming-etl-format-csv-home.html) (read 2026-09-27)
- Apache Hop: [`Beam file output`](https://hop.apache.org/manual/latest/pipeline/transforms/beamfileoutput.html) (read 2026-09-27)
- Apache Hop: [`Neo4j generate CSVs`](https://hop.apache.org/manual/latest/pipeline/transforms/neo4j-gencsv.html) (read 2026-09-27)
- Apache Hop: [`Spark file output`](https://hop.apache.org/manual/next/pipeline/transforms/spark-file-output.html) (read 2026-09-27)
- Apache Hop: [`Text File Output`](https://hop.apache.org/manual/latest/pipeline/transforms/textfileoutput.html) (read 2026-09-27)
- KNIME Analytics Platform: [`CSV Writer`](https://api.hub.knime.com/nodes/*mPMx3pzMHtI9Qk5G?details=full) (read 2026-09-27)
- Apache NiFi: [`CSVRecordSetWriter`](https://nifi.apache.org/components/org.apache.nifi.csv.CSVRecordSetWriter/) (read 2026-09-27)
- OpenRefine: [`Custom tabular exporter`](https://openrefine.org/docs/manual/exporting#custom-tabular-exporter) (read 2026-09-27)
- OpenRefine: [`Tab-separated value (TSV) or Comma-separated value (CSV)`](https://openrefine.org/docs/manual/exporting#export-data) (read 2026-09-27)
- Pentaho Data Integration: [`Hadoop File Output`](https://docs.pentaho.com/pdia-data-integration/9.3-data-integration/pdi-transformation-steps-reference-overview) (read 2026-09-27)
- Pentaho Data Integration: [`S3 File Output`](https://docs.pentaho.com/pdia-data-integration/9.3-data-integration/pdi-transformation-steps-reference-overview) (read 2026-09-27)
- Pentaho Data Integration: [`Text File Output`](https://docs.pentaho.com/pdia-data-integration/9.3-data-integration/pdi-transformation-steps-reference-overview) (read 2026-09-27)
- Pentaho Data Integration: [`Text file output (deprecated)`](https://docs.pentaho.com/pdia-data-integration/9.3-data-integration/pdi-transformation-steps-reference-overview) (read 2026-09-27)
- Polars: [`DataFrame.write_clipboard`](https://docs.pola.rs/api/python/stable/reference/io.html) (read 2026-09-27)
- Polars: [`DataFrame.write_csv`](https://docs.pola.rs/api/python/stable/reference/io.html) (read 2026-09-27)
- Polars: [`LazyFrame.sink_csv`](https://docs.pola.rs/api/python/stable/reference/io.html) (read 2026-09-27)
- RapidMiner Studio: [`Write CSV`](https://docs.rapidminer.com/latest/studio/operators/data_access/files/write/write_csv.html) (read 2026-09-27)
- Tableau Prep: [`Comma Separated Value (.csv)`](https://help.tableau.com/current/prep/en-us/prep_save_share.htm) (read 2026-09-27)
- Talend: [`tFileOutputDelimited`](https://help.qlik.com/talend/en-US/components/8.0/delimited/delimited-component) (read 2026-09-27)
- Talend: [`tFileOutputMSDelimited`](https://help.qlik.com/talend/en-US/components/8.0/ms-delimited/ms-delimited-component) (read 2026-09-27)
- Talend: [`tFileOutputMSPositional`](https://help.qlik.com/talend/en-US/components/8.0/ms-positional/ms-positional-component) (read 2026-09-27)
- Talend: [`tFileOutputPositional`](https://help.qlik.com/talend/en-US/components/8.0/positional/positional-component) (read 2026-09-27)
- VisiData: [`csv (saver)`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/loaders/csv.py#L85) (read 2026-09-23)
- VisiData: [`fixed (saver)`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/loaders/fixed_width.py#L144) (read 2026-09-23)
- VisiData: [`lsv (saver)`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/loaders/lsv.py#L14) (read 2026-09-23)
- VisiData: [`psv (saver)`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/loaders/psv.py#L15) (read 2026-09-23)
- VisiData: [`tsv (saver)`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/loaders/tsv.py#L99) (read 2026-09-23)
- VisiData: [`usv (saver)`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/loaders/usv.py#L16) (read 2026-09-23)
- Yggdrasil Decision Forests: [`csv: (write)`](https://github.com/google/yggdrasil-decision-forests/blob/0a54b57c95ff0cf42ecf0310ace0513a4f32cb65/yggdrasil_decision_forests/dataset/csv_example_writer.h) (read 2026-09-27)
