The EXPORT statement exports tabular data or the results of arbitrary SELECT statements to CSV files.

Using the CockroachDB distributed execution engine, EXPORT parallelizes CSV creation across all nodes in the cluster, making it possible to quickly get large sets of data out of CockroachDB in a format that can be ingested by downstream systems. If you do not need distributed exports, you can use the non-enterprise feature to export tabular data in CSV format.


This is an enterprise feature. Also, it is in beta and is currently undergoing continued testing. Please file a Github issue with us if you identify a bug.

Cancelling export

After the export has been initiated, you can cancel it with CANCEL QUERY.


EXPORT INTO CSV file_location opt_with_options FROM select_stmt TABLE table_name
The EXPORT statement cannot be used within a transaction.

Required privileges

Only members of the admin role can run EXPORT. By default, the root user belongs to the admin role.


Parameter Description
file_location Specify the URL of the file location where you want to store the exported CSV data.

Note: Exports do not generate unique names across exports, so each export should have a unique destination to avoid overwriting.
WITH kv_option Control your export's behavior with these options.
select_stmt Specify the query whose result you want to export to CSV format.
table_name Specify the name of the table you want to export to CSV format.

Export file URL

You can specify the base directory where you want to store the exported .csv files. CockroachDB will create the export file(s) in the specified directory with programmatically generated names (e.g., n1.1.csv, n1.2.csv, n2.1.csv, ...). Each export should have a unique destination to avoid overwriting other exports.

For more information, see the following:

Export options

You can control the EXPORT process's behavior using any of the following key-value pairs as a kv_option.


If not using comma as your column delimiter, you can specify another ASCII character as the delimiter.

Required? No
Key delimiter
Value The ASCII character that delimits columns in your rows
Example To use tab-delimited values: WITH delimiter = e'\t'


Convert SQL NULL values so they match the specified string.

Required? No
Key nullas
Value The string that should be used to represent NULL values. To avoid collisions, it is important to pick nullas values that does not appear in the exported data.
Example To use empty columns as NULL: WITH nullas = ''


Export a table

  WITH delimiter = '|' FROM TABLE bank.customers;

Export using a SELECT statement

  FROM SELECT * FROM bank.customers WHERE id >= 100;

Non-distributed export using the SQL shell

$ cockroach sql -e "SELECT * from bank.customers WHERE id>=100;" --format=csv > my.csv

View a running export

View running exports by using SHOW QUERIES:


Cancel a running export

Use SHOW QUERIES to get a running export's query_id, which can be used to cancel the export:

> CANCEL QUERY '14dacc1f9a781e3d0000000000000001';

Known limitation

EXPORT may fail with an error if the SQL statements are incompatible with DistSQL. In that case, use the non-enterprise feature to export tabular data in CSV format.

See also

Yes No