Inserts rows into a table in ApsaraDB for ClickHouse.
Syntax
INSERT INTO [db.]table [(c1, c2, c3)] VALUES (v11, v12, v13), (v21, v22, v23), ...For columns defined in the table schema but not listed in the statement, ApsaraDB for ClickHouse fills in values using these rules:
| Condition | Behavior |
|---|---|
| A default expression is defined for the column | Evaluates the expression and inserts the result |
| No default expression is defined | Inserts 0 or an empty string |
Use SELECT with INSERT INTO
INSERT INTO [db.]table [(c1, c2, c3)] SELECT ...Columns from the SELECT result map to INSERT INTO columns in strict positional order — column names do not need to match. ApsaraDB for ClickHouse converts data types automatically as needed.
Expression support
Only the VALUES form supports inline expressions such as now() and 1 + 2. Even when using VALUES, avoid inline expressions — evaluating them row by row is inefficient. Compute the values before the insert instead.
Performance considerations
When ApsaraDB for ClickHouse executes an INSERT INTO statement, it processes the data immediately: sorting by primary key and partitioning the data. If the data to be inserted spans multiple months, insert performance degrades significantly.
To maintain high insert throughput:
Write a large volume of data at a time. For example, you can write 100,000 rows of data each time.
Group data before you write the data to an ApsaraDB for ClickHouse cluster.
In the following scenarios, insert performance is not affected:
Data is written in real time.
The data to be written is already sorted by time.