Skip to main content
Inserts data into a specific table or overwrites a specific table with data. From v3.2.0 onwards, INSERT supports writing data into files in remote storage. You can use INSERT INTO FILES() to unload data from the database to remote storage. You can submit an asynchronous INSERT task using SUBMIT TASK.

Syntax

  • Data loading:
  • Data unloading:

Parameters

PROPERTIES

INSERT statements support configuring PROPERTIES from v3.4.0 onwards. Note
  • strict_mode and max_filter_ratio are supported only for INSERT from FILES(). INSERT from tables does not support these properties.
  • From v3.4.0 onwards, when enable_insert_strict is set to true, the system loads only qualified rows. It filters out unqualified rows and returns details about the unqualified rows. Instead, in versions earlier than v3.4.0, when enable_insert_strict is set to true, the INSERT jobs fails when there is an unqualified rows.

Return

Dynamic Overwrite

From v3.4.0 onwards, the database supports a new semantic - Dynamic Overwrite for INSERT OVERWRITE with partitioned tables. Currently, the default behavior of INSERT OVERWRITE is as follows:
  • When overwriting a partitioned table as a whole (that is, without specifying the PARTITION clause), new data records will replace the data in their corresponding partitions. If there are partitions that are not involved, they will be truncated while the others are overwritten.
  • When overwriting an empty partitioned table (that is, with no partitions in it) and specifying the PARTITION clause, the system returns an error ERROR 1064 (HY000): Getting analyzing error. Detail message: Unknown partition 'xxx' in table 'yyy'.
  • When overwriting a partitioned table and specifying a non-existent partition in the PARTITION clause, the system returns an error ERROR 1064 (HY000): Getting analyzing error. Detail message: Unknown partition 'xxx' in table 'yyy'.
  • When overwriting a partitioned table with data records that do not match any of the specified partitions in the PARTITION clause, the system either returns an error ERROR 1064 (HY000): Insert has filtered data in strict mode (if the strict mode is enabled) or filters the unqualified data records (if the strict mode is disabled).
The behavior of the new Dynamic Overwrite semantic is much different: When overwriting a partitioned table as a whole, new data records will replace the data in their corresponding partitions. If there are partitions that are not involved, they will be left alone, instead of being truncated or deleted. And if there are new data records correspond to a non-existent partition, the system will create the partition. Dynamic Overwrite is disabled by default. Set dynamic_overwrite to true to enable it for native tables and for INSERT OVERWRITE on partitioned Paimon tables when you omit the PARTITION clause. INSERT OVERWRITE into an Iceberg table always overwrites only the partitions that receive new data, regardless of this variable. Enable Dynamic Overwrite in the current session:
You can also set it in the hint of the INSERT OVERWRITE statement to allow it take effect for the statement only:. Example:

Usage notes

  • As for the current version, when the database executes the INSERT INTO statement, if any row of data mismatches the destination table format (for example, the string is too long), the INSERT transaction fails by default. You can set the session variable enable_insert_strict to false so that the system filters out the data that mismatches the destination table format and continues to execute the transaction.
  • After INSERT OVERWRITE statement is executed, the database creates temporary partitions for the partitions that store the original data, inserts data into the temporary partitions, and swaps the original partitions with the temporary partitions. All these operations are executed in the Leader FE node. Therefore, if the Leader FE node crashes while executing INSERT OVERWRITE statement, the whole load transaction fails, and the temporary partitions are deleted.
  • The database supports writing into non-expression partitions via the INSERT OVERWRITE statement. However, when writing new data to a partition that did not previously exist, the system will not create the non-existing partition.
About Dynamic Overwrite
  • Dynamic Overwrite only supports expression partitions. When writing new data to a partition that did not previously exist, the system will automatically create the non-existing partition.
  • Dynamic Overwrite supports partitions based on mixed expressions.

Example

Example 1: General usage

The following examples are based on table test, which contains two columns c1 and c2. The c2 column has a default value of DEFAULT.
  • Import a row of data into the test table.
When no destination column is specified, the columns are loaded in sequence into the destination table by default. Therefore, in the above example, the outcomes of the first and second SQL statements are the same. If a destination column (with or without data inserted) uses DEFAULT as the value, the column will use the default value as the loaded data. Therefore, in the above example, the outputs of the third and fourth statements are the same.
  • Load multiple rows of data into the test table at one time.
Because the results of expressions are equivalent, the outcomes of the first and second statements are the same. The outcomes of the third and fourth statements are the same because they both use default value.
  • Import a query statement result into the test table.
  • Import a query result into the test table, and specify partition and label.
  • Overwrite the test table with a query result, and specify partition and label.

Example 2: Load Parquet files from AWS S3 using INSERT from FILES()

The following example inserts data rows from the Parquet file parquet/insert_wiki_edit_append.parquet within the AWS S3 bucket inserttest into the table insert_wiki_edit:

Example 3: INSERT timeout

The following example inserts the data from the source table source_wiki_edit to the target table insert_wiki_edit with the timeout duration set to 2 seconds.
If you want to ingest large a dataset, you can set a larger value for timeout, or for the session variable insert_timeout.

Example 4: INSERT strict mode and max filter ratio

The following example inserts data rows from the Parquet file parquet/insert_wiki_edit_append.parquet within the AWS S3 bucket inserttest into the table insert_wiki_edit, enables strict mode to filter the unqualified data records, and tolerates at most 10% of error data:

Example 5: INSERT match column by name

The following example matches each column in the source and target tables by their names:
In this case, changing the order of channel and user will not change the column mapping.