DLO
DLO

Reputation: 1194

How to insert large amount of data into a ClickHouse DB?

I have an instance of a ClickHouse server running and I have successfully connected to it through a client. I'm using Tabix.io to run my queries. I have created a DB and a table called "names". I want to input a lot of randomly generated names inside that table. I know that running multiple commands like this:

insert into names (id, first_name, last_name) values (1, 'Stephana', 'Bromell');
insert into names (id, first_name, last_name) values (2, 'Babita', 'Leroux');
insert into names (id, first_name, last_name) values (3, 'Pace', 'Christofides');
...
insert into names (id, first_name, last_name) values (999, 'Ralph', 'Jackson');

is not supported and therefore it is only the first query that is executed. In other words only Stephana Bromell appear in the "names" table.

What is the ClickHouse alternative for inserting larger amounts of data?

Upvotes: 6

Views: 6223

Answers (2)

Yongfeng
Yongfeng

Reputation: 686

How about batch inserting using http client with CSV

  1. create csv file (names.csv) with content:
1,Stephana,Bromell
2,Babita,Leroux
3,Pace,Christofides
...
999,Ralph,Jackson
  1. call HTTP API:
curl -i -X POST \
   -T "./names.csv" \
 'http://localhost:8123/?query=INSERT%20INTO%20names%20FORMAT%20CSV'

Upvotes: 5

Denny Crane
Denny Crane

Reputation: 13275

multiple values in a single insert.

insert into names (id, first_name, last_name) values (1, 'Stephana', 'Bromell') (2, 'Babita', 'Leroux') (3, 'Pace', 'Christofides') (999, 'Ralph', 'Jackson');

Upvotes: 5

Related Questions