tzortzik
tzortzik

Reputation: 5143

cassandra insert as json using array of objects

Currently in the cassandra doc it says that this will work:

INSERT INTO cycling.cyclist_category JSON '{
  "category" : "GC", 
  "points" : 780, 
  "id" : "829aa84a-4bba-411f-a4fb-38167a987cda",
  "lastname" : "SUTHERLAND" }';

Is there any way I can obtain something like this in an easy way?

INSERT INTO cycling.cyclist_category JSON '[{
  "category" : "GC", 
  "points" : 780, 
  "id" : "829aa84a-4bba-411f-a4fb-38167a987cda",
  "lastname" : "SUTHERLAND" }, {
  "category" : "GC", 
  "points" : 780, 
  "id" : "829aa84a-4bba-411f-a4fb-38167a987cda",
  "lastname" : "SUTHERLAND" }]';

Notice the array.

Upvotes: 1

Views: 810

Answers (1)

Samantha Blowers
Samantha Blowers

Reputation: 251

You could write a python script that uses the Cassandra driver to iterate through the array and insert each value.

session = cluster.connect()
arr = [..]
for data in arr:
  session.execute("INSERT INTO cycling.cyclist_category JSON " + json.dumps(data));

Upvotes: 3

Related Questions