liveBook · Manning

COPY TO

As explained in DuckDB in Action

The COPY TO clause is a DuckDB SQL syntax for writing query results or table contents to an external file.

COPY TO writes query results to an external file, making it useful for exporting transformed data in command-line pipelines. CSV output can be redirected, while Parquet output uses COPY with an explicit destination and format. section 2.5.1 section 5.4

Export Western European indicators to Parquet

duckdb -s "COPY ( SELECT Country, Population, Birthrate, Deathrate FROM read_csv_auto('https://bit.ly/3KoiZR0') WHERE trim(region) = 'WESTERN EUROPE' ) TO 'western_europe.parquet' (FORMAT PARQUET)". The resulting file can be read with DuckDB or another Parquet reader.

How DuckDB in Action covers it

How deep it goes
Demonstrates destination syntax, output formats, memory limits, compression, and row-group sizing without cataloging all COPY options.
Examples
Uses Western European demographic indicators and joined ATP rankings and player data as export examples.
What it assumes
Assumes familiarity with SELECT queries, CSV input, and invoking DuckDB from the command line.
What you can do after
Build it from scratch by exporting selected, transformed query results to CSV or explicitly formatted Parquet files.
How it connects
Connects SQL queries with CSV, Parquet, DuckDB CLI pipelines, memory limits, compression, and file inspection.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of DuckDB in Action. The section links point to the parts of the book it draws on.