Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMPORT INTO with default expressions and computed columns #8764

Merged
merged 3 commits into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-value.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-value.html) expression for any of its columns.

## See also

Expand Down
28 changes: 26 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,33 @@ 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()`

### 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