- Introduction
- Quick Start
- Table Design
- Data Loading
- Overview of data loading
- Load data from a local file system or a streaming data source using HTTP push
- Load data from HDFS or cloud storage
- Routine Load
- Spark Load
- Insert Into
- Change data through loading
- Transform data at loading
- Json Loading
- Synchronize data from MySQL
- Load data by using flink-connector-starrocks
- DataX Writer
- Data Export
- Using StarRocks
- Reference
- SQL Reference
- User Account Management
- Cluster Management
- ADMIN CANCEL REPAIR
- ADMIN CHECK TABLET
- ADMIN REPAIR
- ADMIN SET CONFIG
- ADMIN SET REPLICA STATUS
- ADMIN SHOW CONFIG
- ADMIN SHOW REPLICA DISTRIBUTION
- ADMIN SHOW REPLICA STATUS
- ALTER SYSTEM
- CANCEL DECOMMISSION
- CREATE FILE
- DROP FILE
- INSTALL PLUGIN
- SHOW BACKENDS
- SHOW BROKER
- SHOW FILE
- SHOW FRONTENDS
- SHOW FULL COLUMNS
- SHOW INDEX
- SHOW PLUGINS
- SHOW TABLE STATUS
- UNINSTALL PLUGIN
- DDL
- ALTER DATABASE
- ALTER TABLE
- ALTER VIEW
- BACKUP
- CANCEL BACKUP
- CANCEL RESTORE
- CREATE DATABASE
- CREATE INDEX
- CREATE MATERIALIZED VIEW
- CREATE REPOSITORY
- CREATE RESOURCE
- CREATE TABLE AS SELECT
- CREATE TABLE LIKE
- CREATE TABLE
- CREATE VIEW
- CREATE FUNCTION
- DROP DATABASE
- DROP INDEX
- DROP MATERIALIZED VIEW
- DROP REPOSITORY
- DROP RESOURCE
- DROP TABLE
- DROP VIEW
- DROP FUNCTION
- HLL
- RECOVER
- RESTORE
- SHOW RESOURCES
- SHOW FUNCTION
- TRUNCATE TABLE
- DML
- ALTER ROUTINE LOAD
- BROKER LOAD
- CANCEL LOAD
- DELETE
- EXPORT
- GROUP BY
- INSERT
- PAUSE ROUTINE LOAD
- RESUME ROUTINE LOAD
- ROUTINE LOAD
- SELECT
- SHOW ALTER
- SHOW BACKUP
- SHOW DATA
- SHOW DATABASES
- SHOW DELETE
- SHOW DYNAMIC PARTITION TABLES
- SHOW EXPORT
- SHOW LOAD
- SHOW PARTITIONS
- SHOW PROPERTY
- SHOW REPOSITORIES
- SHOW RESTORE
- SHOW ROUTINE LOAD
- SHOW ROUTINE LOAD TASK
- SHOW SNAPSHOT
- SHOW TABLES
- SHOW TABLET
- SHOW TRANSACTION
- SPARK LOAD
- STOP ROUTINE LOAD
- STREAM LOAD
- Data Types
- Auxiliary Commands
- Function Reference
- Java UDFs
- Window Function
- Date Functions
- convert_tz
- curdate
- current_timestamp
- curtime
- datediff
- date_add
- date_format
- date_sub
- date_trunc
- day
- dayname
- dayofmonth
- dayofweek
- dayofyear
- from_days
- from_unixtime
- hour
- minute
- month
- monthname
- now
- quarter
- second
- str_to_date
- timediff
- timestampadd
- timestampdiff
- to_date
- to_days
- unix_timestamp
- utc_timestamp
- weekofyear
- year
- hours_diff
- minutes_diff
- months_diff
- seconds_diff
- weeks_diff
- years_diff
- Aggregate Functions
- Geographic Functions
- String Functions
- JSON Functions
- Overview of JSON functions and operators
- JSON constructor functions
- JSON query and processing functions
- JSON operators
- Aggregate Functions
- Bitmap Functions
- Array Functions
- cast function
- hash function
- Cryptographic Functions
- Math Functions
- Utility Functions
- System variables
- Error code
- System limits
- SQL Reference
- Administration
- FAQ
- Deploy
- Data Migration
- SQL
- Other FAQs
- Benchmark
- Developers
- Contribute to StarRocks
- Code Style Guides
- Use the debuginfo file for debugging
- Development Environment
- Trace Tools
- Integration
INSERT
description
Syntax
INSERT INTO table_name
[ PARTITION (p1, ...) ]
[ WITH LABEL label]
[ (column [, ...]) ]
[ [ hint [, ...] ] ]
{ VALUES ( { expression | DEFAULT } [, ...] ) [, ...] | query }
Parameters
tablet_name: Destination table of imported data. It can also be in `db_name.table_name` form.
partitions: Specifies the partition to be imported.It must be partitions existent in`table_name`. Multiple partition names are separated by commas.
label: Specifies a label for the Insert task.
column_name: Specified the destination column which must be existnent in `table_name`.
expression: The corresponding expression that needs to be assigned to a column.
DEFAULT: Set default value to the corresponding column.
query: A normal query. The query results will be written to the target.
hint: some indicators used to indicate the execution behavior of `INSERT`. Both `streaming` and the default non `streaming` methods use the synchronous method to complete the execution of the `INSERT` statement.
In the non `streaming` mode, a label will be returned after execution, which is convenient for users to query the imported status through `SHOW LOAD`.
Note
When the INSERT
statement is currently executed, the default behaviour is filtering for data that does not conform to the target table format, such as super long string. However, for business scenarios that require that data cannot be filtered, you can set the session variable enable_insert_strict
as true
to ensure thatINSERT
will not be executed successfully when data is filtered out.
example
Thetest
table contains two columnsc1
and c2
.
Import a row of data into the
test
table.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
c2
column to complete data import.Import multiple rows of data into the
test
table at one time.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 effects of the first and second statements are the same. Import two pieces of data into the
test
table at one time. The effects of the third and fourth statements are known. Use the default value of columnc2
to import two pieces of data into thetest
table.Import a query statement result into the
test
table.INSERT INTO test SELECT * FROM test2; INSERT INTO test (c1, c2) SELECT * from test2;
Import a query statement result into the
test
table, and specify partition and label.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 is as efficient as not filling in.
Since the previous import methods of StarRocks were asynchronous, in order to be compatible with the old usage habits, the
INSERT
statement without streaming will still return a label. The user needs to view the status of thelabel
import job through theSHOW LOAD
command.
keyword
INSERT