COPY in DuckDB reads and writes CSV, Parquet, and JSON files
Answer: COPY reads a file into a table or writes a table to a file. The examples show CSV, Parquet, and JSON.
Reading
COPY lineitem FROM 'lineitem.csv'auto-detected CSV optionsCOPY lineitem FROM 'lineitem.csv' (DELIMITER '|')manually specified CSV optionsCOPY lineitem FROM 'lineitem.pq' (FORMAT parquet)a Parquet fileCOPY lineitem FROM 'lineitem.json' (FORMAT json, AUTO_DETECT true)a JSON file
Read a CSV file into the lineitem table, using double quotes, or omitting quotes.
Writing
COPY lineitem TO 'lineitem.csv' (FORMAT csv, DELIMITER '|', HEADER) writes a table to a CSV file. Write a table to a CSV file, using double quotes, or omitting quotes.
Operators in the engine
PhysicalCopyDatabase uses a target_database and create_info entries for SCHEMA_ENTRY, VIEW, and TABLE catalog types. PhysicalCopyToFile tracks the directory relative to the COPY target, with "/" separators. The directory is relative to the COPY target, with "/" separators. Use COPY FROM and COPY TO in SQL for file import and export.
See also
Claims
- id: C1 claim: COPY can read a CSV file into a table, with auto-detected options or an explicit delimiter. source: S1 evidence: "COPY lineitem FROM 'lineitem.csv';"
- id: C2 claim: COPY can also read Parquet or JSON by setting FORMAT, and can write a table back out. source: S1 evidence: "COPY lineitem FROM 'lineitem.pq' (FORMAT parquet);"
- id: C3 claim: The execution engine has a PhysicalCopyToFile operator whose COPY target path can be a directory-relative name. source: S2 evidence: "The directory relative to the COPY target, with \"/\" separators"
Sources
- [S1] COPY Statement. DuckDB. https://duckdb.org/docs/2.0/sql/statements/copy.html . License: MIT. Accessed 2026-11-20.
- [S2] PhysicalCopyDatabase and PhysicalCopyToFile. DuckDB. https://raw.githubusercontent.com/duckdb/duckdb/main/src/execution/operator/persistent/physical_copy_database.cpp . License: MIT. Accessed 2026-11-20.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: DuckDB, COPY Statement; DuckDB, PhysicalCopyDatabase and PhysicalCopyToFile. MIT; MIT. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: DuckDB, COPY Statement; DuckDB, PhysicalCopyDatabase and PhysicalCopyToFile. MIT; MIT.
Cite this
iinventedlight. 2026. "COPY in DuckDB reads and writes CSV, Parquet, and JSON files." iinventedlight Library, iil:note:7t21n5nb, version of 2026-11-20. https://iinventedlight.com/library/notes/duckdb-copy/. License: CC-BY-4.0.
@misc{iil_note_7t21n5nb,
author = {{iinventedlight}},
title = {{COPY in DuckDB reads and writes CSV, Parquet, and JSON files}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-20},
url = {https://iinventedlight.com/library/notes/duckdb-copy/},
note = {Permanent ID iil:note:7t21n5nb. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- duckdb-copy.table.json (table; CC-BY-4.0)
- duckdb-copy.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/duckdb-copy.md.