As of v22.1, certain
IMPORT TABLE statements that defined the table schema inline are not supported. See for more details. To import data into a new table, use followed by . For an example, read .Step 1. Export data to CSV
Please refer to the documentation of your database for instructions on exporting data to CSV. You will need to export one CSV file per table, with the following requirements:- Files must be in valid CSV format, with the caveat that the delimiter must be a single character. To use a character other than comma (such as a tab), set a custom delimiter using the .
- Files must be UTF-8 encoded.
- If one of the following characters appears in a field, the field must be enclosed by double quotes:
- delimiter (
,by default) - double quote (
") - newline (
\n) - carriage return (
\r)
- delimiter (
- If double quotes are used to enclose fields, then a double quote appearing inside a field must be escaped by preceding it with another double quote. For example:
"aaa","b""bb","ccc". - If a column is of type , it can either be a valid UTF-8 string or a beginning with
\x. For example, a field whose value should be the bytes1,2would be written as\x0102.
Step 2. Host the files where the cluster can access them
Each node in the CockroachDB cluster needs to have access to the files being imported. There are several ways for the cluster to access the data; for more information on the types of storage can pull from, see the following:Step 3. Import the CSV
You will need to write a statement that matches the schema of the table data you’re importing. For example, to import the data fromemployees.csv into an employees table, issue the following statement to create the table:
IMPORT INTO to import the data into the new table:
- The column order in your schema must match the column order in the file being imported.
- You will need to run to add any foreign key relationships.
Configuration Options
The following options are available toIMPORT ... CSV:
Column delimiter
Thedelimiter option is used to set the Unicode character that marks where each column ends. Default: ,.
Example usage:
Comment syntax
Thecomment option determines which Unicode character marks the rows in the data to be skipped.
Example usage:
Skip header rows
Theskip option determines the number of header rows to skip when importing a file.
Example usage:
Null strings
Thenullif option specifies a column value that should be converted to NULL.
To match the
nullif setting, a CSV input value must be unquoted. For details, see .File compression
Thecompress option defines which decompression codec should be used on the CSV file to be imported. Options include:
gzip: Uses the gzip algorithm to decompress the file.bzip: Uses the bzip algorithm to decompress the file.none: Disables decompression.auto: Default. Guesses based on file extension (‘none’ for.csv, ‘gzip’ for.gz, ‘bzip’ for.bzand.bz2).

