COPY lets you export any ParadeDB table or query result straight to a CSV file on the server.
CSV is a universal interchange format. Exporting from ParadeDB with COPY lets you move data into spreadsheets, BI tools, or other databases without additional ETL steps.
Use COPY table_name [ (column_list) ] TO 'file_path' WITH (FORMAT csv, HEADER boolean, DELIMITER char, FORCE_QUOTE col_list).
Ensure the Postgres user has write permission to the target directory, e.g., /var/lib/postgresql/exports/.
Execute COPY from psql or your SQL editor. Include HEADER for column names and quote settings for clean output.
HEADER true writes column names. DELIMITER defaults to a comma but can change to \t for TSV. FORCE_QUOTE keeps text columns quoted, preventing embedded commas from breaking rows.
Wrap your SELECT inside COPY: COPY (SELECT * FROM Products WHERE stock > 0) TO 'in_stock_products.csv' WITH (FORMAT csv, HEADER);
Create an exports directory owned by the postgres OS user. Use absolute paths. Sanitize file names via format('%I_%s.csv', table_name, to_char(now(),'YYYYMMDD')) to automate backups.
Omitting HEADER causes column misalignment in Excel. Writing to a path without permissions raises “could not open file” errors.
Use \copy in psql which streams data to your local shell rather than the server, e.g., \copy Customers TO 'customers.csv' CSV HEADER.
Yes. List the columns after the table name or use a SELECT inside COPY to project only the columns you need.
Set DELIMITER '\t' in the WITH clause. Most spreadsheet tools automatically detect TSV files.
PostgreSQL 15+ supports PROGRAM, so you can pipe COPY output to gzip: COPY Products TO PROGRAM 'gzip > /exports/products.csv.gz' WITH (FORMAT csv, HEADER);