ClickHouse Batch Data Insertion (Using INSERT INTO and _bulk APIs)
In the Field of ClickHouse
Batch inserting data is an important feature of ClickHouse, which allows multiple rows to be inserted into a table in one operation, thereby improving insertion speed and efficiency.
Using INSERT INTO Statements
Using INSERT INTO statements can batch insert data into ClickHouse tables. The following example shows how to use this statement:
INSERT INTO table_name (column1, column2) VALUES ('value1', 'value2'),
('value3', 'value4'),
('value5', 'value6');
Using Bulk API
Bulk API is an API of ClickHouse that provides an efficient method to batch insert data into tables. Data can be transmitted by sending a request body using the Bulk API.
Example Request Body for Bulks API:
[
{"column1": "value1", "column2": "value2"},
{"column1": "value3", "column2": "value4"},
{"column1": "value5", "column2": "value6"}
]
Example Request for Bulks API:
curl -X POST \
http://localhost:9000/api/bulk/insert/ \
-H 'Content-Type: application/json' \
-d '[{"column1": "value1", "column2": "value2"}, {"column1": "value3", "column2": "value4"}, {"column1": "value5", "column2": "value6"}]'
Advantages
Using the method of batch inserting data brings the following advantages:
- Improve INSERT Speed: By being able to insert multiple rows in one operation, it improves insertion speed.
- Enhance Performance: Reduce unnecessary network transmission and CPU burden, improving overall performance.
Conclusion
Using the method of batch inserting data can improve INSERT speed and efficiency in ClickHouse. By understanding Bulk API and INSERT INTO statements within ClickHouse, efficient data exchange can be achieved.