netfreak30
netfreak30

Reputation: 316

how to insert data in Cassandra with custom datatype?

I have created table for users with following query using cqlsh command line. Use case is to store company_id with role_id for every users in users table schema.

CREATE TABLE users (id uuid PRIMARY KEY,name text,company list<frozen<map<uuid, set<uuid>>>>)

Now, I want to insert data in this table. I'm using following query to insert data, but I'm getting syntactical errors.

insert into users (id,name, company) VALUES (now(),'darshana', [12f64b58-423f-408b-a6e5-42c69208511b:[{12f64b58-423f-408b-a6e5-42c69208511b}]]);

I have tried several solutions but none worked for me.

Can any one help me out?

Upvotes: 0

Views: 210

Answers (1)

medvekoma
medvekoma

Reputation: 1179

The following syntax should work:

insert into users (id, name, company) VALUES ( 
  now(), 'darshana', 
  [{12f64b58-423f-408b-a6e5-42c69208511b:{12f64b58-423f-408b-a6e5-42c69208511b}}]
);

List literals are enclosed in [], maps and sets in {}. Look for set_literal in http://cassandra.apache.org/doc/latest/cql/types.html.

Upvotes: 3

Related Questions