Syntax
-
Data loading:
-
Data unloading:
Parameters
PROPERTIES
INSERT statements support configuring PROPERTIES from v3.4.0 onwards.
Note
strict_modeandmax_filter_ratioare supported only for INSERT from FILES(). INSERT from tables does not support these properties.- From v3.4.0 onwards, when
enable_insert_strictis set totrue, 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, whenenable_insert_strictis set totrue, 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).
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:
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_stricttofalseso 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.
- 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 tabletest, which contains two columns c1 and c2. The c2 column has a default value of DEFAULT.
- Import a row of data into the
testtable.
- Load multiple rows of data into the
testtable at one time.
- Import a query statement result into the
testtable.
- Import a query result into the
testtable, and specify partition and label.
- Overwrite the
testtable 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 bucketinserttest into the table insert_wiki_edit:
Example 3: INSERT timeout
The following example inserts the data from the source tablesource_wiki_edit to the target table insert_wiki_edit with the timeout duration set to 2 seconds.
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 bucketinserttest 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:channel and user will not change the column mapping.