Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

COPY TO

Export table data to a CSV file or stdout.

Syntax

COPY [keyspace.]table [(column1, column2, ...)] TO 'filename'|STDOUT [WITH option = value [AND ...]]

Options

OptionDefaultDescription
DELIMITER,Field delimiter character
QUOTE"Quote character for fields
ESCAPE\\Escape character
HEADERfalseInclude column headers in first row
NULL(empty)String to represent NULL values
DATETIMEFORMATfrom configTimestamp format
ENCODINGutf-8Output encoding
FLOATPRECISION5Decimal digits for float values
DOUBLEPRECISION12Decimal digits for double values
DECIMALSEP.Decimal separator
THOUSANDSSEPThousands separator
BOOLSTYLETrue,FalseBoolean representation
PAGESIZE1000Rows per page
MAXOUTPUTSIZEunlimitedMaximum rows to export

Examples

-- Export entire table
COPY users TO '/tmp/users.csv';

-- Export specific columns with headers
COPY users (id, name, email) TO '/tmp/users.csv' WITH HEADER = true;

-- Export to stdout
COPY users TO STDOUT;

-- Export with custom delimiter
COPY users TO '/tmp/users.tsv' WITH DELIMITER = '\t' AND HEADER = true;

Notes

  • Disabled when --no-file-io is used (except TO STDOUT).
  • See the COPY Guide for detailed usage and performance tips.