2

I am new in Cassandra. I have created one sample table. Right now facing problem during insert.

created employee like below :

create table employee(
  emp_id int PRIMARY KEY,
  first_name text,
  last_name text,
  department text,
  skillswithrank map
);

Written query :

INSERT INTO company.employee(emp_id,first_name,last_name,department,skillswithrank )
 VALUES (1,'sam', 'watson', 'IT', [{"nodejs":4},{"angularjs":4},{"expressjs":4}]);

I am stuck at this point.

Alex Ott
  • 80,552
  • 8
  • 87
  • 132

1 Answers1

2

You're trying to insert a list of maps, instead of map, so your insert doesn't match to table definition. Plus you're using incorrect syntax for strings in the map.

you need to write insert as:

INSERT INTO company.employee(emp_id,first_name,last_name,department,skillswithrank )
  VALUES (1,'sam', 'watson', 'IT', {'nodejs':4, 'angularjs':4, 'expressjs':4]);
Alex Ott
  • 80,552
  • 8
  • 87
  • 132
  • Thanks for the reply. company.employee is a demo table. I have another table, In that, I am trying to insert nested JSON. But I am unable to Insert. – sameer vedpathak Nov 22 '18 at 12:25
  • please share the real table structure, what you want to insert, and what error you get - otherwise it's impossible to answer the question – Alex Ott Nov 22 '18 at 12:31
  • Please refer below structure : create table company.executionInput ( ExecutionInputID bigint PRIMARY KEY, ExecutionLogID bigint, Acc_Type text, Email_Valid int, Country text, Customer_Accounts map, CurrentOrder_List map ); – sameer vedpathak Nov 22 '18 at 13:05
  • I am getting error like : Invalid list literal for customer_accounts of type map – sameer vedpathak Nov 22 '18 at 13:06
  • I wrote in my answer that you have map declared in the table, but you're inserting a list of maps instead... – Alex Ott Nov 22 '18 at 13:13
  • Can we Insert list of maps in Cassandra table? If Yes then can you please suggest me? – sameer vedpathak Nov 22 '18 at 13:29