简体   繁体   中英

Insert multiple records at once in Cassandra

I've been researching a lot about how to insert multiple records in direct cassandra cqlsh console. I found something about batch, so I thought of using it with a loop (for, while) but it seems that Cassandra does not support batch.

How could insert multiple records in direct cassandra console? There is something like stored procedure in cassandra?

Cassandra does not (at this time) have stored procedures, but you should be able to accomplish this with a batch statement . Essentially you should be able to encapsulate multiple INSERT s inside of BEGIN BATCH and APPLY BATCH statements. This example is from the DataStax documentation on batch operations.

BEGIN BATCH
  INSERT INTO purchases (user, balance) VALUES ('user1', -8) USING TIMESTAMP 19998889022757000;
  INSERT INTO purchases (user, expense_id, amount, description, paid)
    VALUES ('user1', 1, 8, 'burrito', false);
APPLY BATCH;

Check the doc linked above for more information.

Edit:

If you are meaning to INSERT several million records at once, then you should consider other methods. The cqlsh COPY command is a viable alternative (for a few million records or less) or the Cassandra Bulk Loader for 10 million or more.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM