5

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?

DLO
  • 914
  • 1
  • 13
  • 30
  • consider using [Buffer Table Engine](https://clickhouse.tech/docs/en/engines/table-engines/special/buffer/). See related answer - https://stackoverflow.com/a/52437466/303298 – vladimir Dec 21 '20 at 16:04
  • 1
    Does this answer your question? [Multiple small inserts in clickhouse](https://stackoverflow.com/questions/40592010/multiple-small-inserts-in-clickhouse) – vladimir Dec 21 '20 at 16:06
  • @vladimir Thanks! I will definately use buffer tables at a later phase. – DLO Dec 22 '20 at 10:07

2 Answers2

5

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');

Denny Crane
  • 11,574
  • 2
  • 19
  • 30
4

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'
Yongfeng
  • 666
  • 7
  • 22