--- { "title": "INSERT", "language": "en" } --- ## INSERT ### Name INSERT ### Description The change statement is to complete the data insertion operation. ```sql INSERT INTO table_name [ PARTITION (p1, ...) ] [ WITH LABEL label] [ (column [, ...]) ] [ [ hint [, ...] ] ] { VALUES ( { expression | DEFAULT } [, ...] ) [, ...] | query } ```` Parameters > tablet_name: The destination table for importing data. Can be of the form `db_name.table_name` > > partitions: Specify the partitions to be imported, which must be partitions that exist in `table_name`. Multiple partition names are separated by commas > > label: specify a label for the Insert task > > column_name: The specified destination column, must be a column that exists in `table_name` > > expression: the corresponding expression that needs to be assigned to a column > > DEFAULT: let the corresponding column use the default value > > query: a common query, the result of the query will be written to the target > > hint: some indicator used to indicate the execution behavior of `INSERT`. Both `streaming` and the default non-`streaming` method use synchronous mode to complete `INSERT` statement execution > The non-`streaming` method will return a label after the execution is completed, which is convenient for users to query the import status through `SHOW LOAD` Notice: When executing the `INSERT` statement, the default behavior is to filter the data that does not conform to the target table format, such as the string is too long. However, for business scenarios that require data not to be filtered, you can set the session variable `enable_insert_strict` to `true` to ensure that `INSERT` will not be executed successfully when data is filtered out. ### Example The `test` table contains two columns `c1`, `c2`. 1. Import a row of data into the `test` table ```sql INSERT INTO test VALUES (1, 2); INSERT INTO test (c1, c2) VALUES (1, 2); INSERT INTO test (c1, c2) VALUES (1, DEFAULT); INSERT INTO test (c1) VALUES (1); ```` The first and second statements have the same effect. When no target column is specified, the column order in the table is used as the default target column. The third and fourth statements express the same meaning, use the default value of the `c2` column to complete the data import. 2. Import multiple rows of data into the `test` table at one time ```sql INSERT INTO test VALUES (1, 2), (3, 2 + 2); INSERT INTO test (c1, c2) VALUES (1, 2), (3, 2 * 2); INSERT INTO test (c1) VALUES (1), (3); INSERT INTO test (c1, c2) VALUES (1, DEFAULT), (3, DEFAULT); ```` The first and second statements have the same effect, import two pieces of data into the `test` table at one time The effect of the third and fourth statements is known, and the default value of the `c2` column is used to import two pieces of data into the `test` table 3. Import a query result into the `test` table ```sql INSERT INTO test SELECT * FROM test2; INSERT INTO test (c1, c2) SELECT * from test2; ```` 4. Import a query result into the `test` table, specifying the partition and label ```sql INSERT INTO test PARTITION(p1, p2) WITH LABEL `label1` SELECT * FROM test2; INSERT INTO test WITH LABEL `label1` (c1, c2) SELECT * from test2; ```` Asynchronous import is actually a synchronous import encapsulated into asynchronous. Filling in streaming and not filling in **execution efficiency is the same**. Since the previous import methods of Doris are all asynchronous import methods, in order to be compatible with the old usage habits, the `INSERT` statement without streaming will still return a label. Users need to view the `label` import job through the `SHOW LOAD` command. state. ### Keywords INSERT ### Best Practice