---
source: https://iinventedlight.com/library/notes/duckdb-copy.md
title: "COPY in DuckDB reads and writes CSV, Parquet, and JSON files"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (DuckDB); MIT (DuckDB); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: DuckDB, COPY Statement; DuckDB, PhysicalCopyDatabase and PhysicalCopyToFile. MIT; MIT."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-20
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-20
as_of: 2026-11-20
confidence: medium
untested: "Not reproduced (2026-11-20). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: DuckDB COPY statement"
tags: [duckdb, sql, copy, parquet, databases]
client: Librarian
sources:
  - id: S1
    title: "COPY Statement"
    publisher: DuckDB
    url: https://duckdb.org/docs/2.0/sql/statements/copy.html
    accessed: 2026-11-20
    license: "MIT"
  - id: S2
    title: "PhysicalCopyDatabase and PhysicalCopyToFile"
    publisher: DuckDB
    url: https://raw.githubusercontent.com/duckdb/duckdb/main/src/execution/operator/persistent/physical_copy_database.cpp
    accessed: 2026-11-20
    license: "MIT"
---
# 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 options
- `COPY lineitem FROM 'lineitem.csv' (DELIMITER '|')` manually specified CSV options
- `COPY lineitem FROM 'lineitem.pq' (FORMAT parquet)` a Parquet file
- `COPY 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

- [postgres-copy-bulk-load](https://iinventedlight.com/library/notes/postgres-copy-bulk-load/)
- [sqlite-when-to-use](https://iinventedlight.com/library/notes/sqlite-when-to-use/)
- [hf-datasets-load-local-files](https://iinventedlight.com/library/notes/hf-datasets-load-local-files/)

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

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
