Skip to content

Commit

Permalink
IMPORT INTO with default expressions and computed columns
Browse files Browse the repository at this point in the history
Closes #8585.
Closes #8291.
Closes #8105.
Closes #8289.
Closes #8106.
Closes #7863.
Closes #8419.
  • Loading branch information
Lauren committed Oct 27, 2020
1 parent 6e43d48 commit 1301850
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions v19.2/import-into.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ Google Cloud:
~~~ sql
> SET CLUSTER SETTING kv.bulk_io_write.max_rate = '10MB';
~~~
- `IMPORT INTO` cannot be used on a table with a [`DEFAULT`](default.html) expression for any of its columns.

## See also

Expand Down
3 changes: 2 additions & 1 deletion v20.1/import-into.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ summary: Import CSV data into an existing CockroachDB table.
toc: true
---

The `IMPORT INTO` [statement](sql-statements.html) imports CSV data into an [existing table](create-table.html). `IMPORT INTO` appends new rows onto the table.
The `IMPORT INTO` [statement](sql-statements.html) imports CSV or Avro data into an [existing table](create-table.html). `IMPORT INTO` appends new rows onto the table.

## Considerations

Expand Down Expand Up @@ -244,6 +244,7 @@ For more detailed information about importing data from Avro and examples, see [
~~~ sql
> SET CLUSTER SETTING kv.bulk_io_write.max_rate = '10MB';
~~~
- `IMPORT INTO` cannot be used on a table with a [`DEFAULT`](default.html) expression for any of its columns.

## See also

Expand Down
32 changes: 30 additions & 2 deletions v20.2/import-into.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ summary: Import CSV data into an existing CockroachDB table.
toc: true
---

The `IMPORT INTO` [statement](sql-statements.html) imports CSV data into an [existing table](create-table.html). `IMPORT INTO` appends new rows onto the table.
The `IMPORT INTO` [statement](sql-statements.html) imports CSV or Avro data into an [existing table](create-table.html). `IMPORT INTO` appends new rows onto the table.

## Considerations

Expand Down Expand Up @@ -70,9 +70,37 @@ For instructions and working examples showing how to migrate data from other dat
Before using `IMPORT INTO`, you should have:

- An existing table to import into (use [`CREATE TABLE`](create-table.html)).

<span class="version-tag">New in v20.2:</span> `IMPORT INTO` supports [computed columns](computed-columns.html) and the [`DEFAULT` expressions listed below](#supported-default-expressions).

- The CSV or Avro data you want to import, preferably hosted on cloud storage. This location must be equally accessible to all nodes using the same import file location. This is necessary because the `IMPORT INTO` statement is issued once by the client, but is executed concurrently across all nodes of the cluster. For more information, see the [Import file location](#import-file-location) section below.

{% include {{ page.version.version }}/sql/import-into-default-value.md %}
#### Supported `DEFAULT` expressions

<span class="version-tag">New in v20.2:</span> `IMPORT INTO` supports [computed columns](computed-columns.html) and the following [`DEFAULT`](default-value.html) expressions:

- Constant `DEFAULT` expressions, which are expressions that return the same value in different statements. Examples include:

- Literals (booleans, strings, integers, decimals, dates)
- Functions where each argument is a constant expression and the functions themselves depend solely on their arguments (e.g., arithmetic operations, boolean logical operations, string operations).

- Current [`TIMESTAMP`](timestamp.html) functions that record the transcation timestamp, which include:

- `current_date()`
- `current_timestamp()`
- `localtimestamp()`
- `now()`
- `statement_timestamp()`
- `timeofday()`
- `transaction_timestamp()`

- `random()`
- `gen_random_uuid`
- `unique_rowid()`

{{site.data.alerts.callout_info}}
Non-targeted columns with constant default expressions are not required to be nullable.
{{site.data.alerts.end}}

### Available storage

Expand Down
4 changes: 3 additions & 1 deletion v20.2/import.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ Your `IMPORT` statement must reference a `CREATE TABLE` statement representing t

We also recommend [specifying all secondary indexes you want to use in the `CREATE TABLE` statement](create-table.html#create-a-table-with-secondary-and-inverted-indexes). It is possible to [add secondary indexes later](create-index.html), but it is significantly faster to specify them during import.

{% include {{ page.version.version }}/sql/import-default-value.md %}
{{site.data.alerts.callout_info}}
<span class="version-tag">New in v20.2:</span> `IMPORT` supports [computed columns](computed-columns.html) for Avro and Postgres dump files only. To import CSV data to a table with a computed column or `DEFAULT` expression, use [`IMPORT INTO`](import-into.html).
{{site.data.alerts.end}}

{{site.data.alerts.callout_info}}
By default, the [Postgres][postgres] and [MySQL][mysql] import formats support foreign keys. However, the most common dependency issues during import are caused by unsatisfied foreign key relationships that cause errors like `pq: there is no unique constraint matching given keys for referenced table tablename`. You can avoid these issues by adding the [`skip_foreign_keys`](#import-options) option to your `IMPORT` statement as needed. Ignoring foreign constraints will also speed up data import.
Expand Down

0 comments on commit 1301850

Please sign in to comment.