Search code examples
databasecassandracqlcqlsh

Getting error while inserting data into Cassandra


I am trying to insert data into my cassandra db table, however I keep getting error and not able to figure out the exact problem.

This is my table schema

CREATE TABLE discoveryassignment.connector_assignments (
    connector_id text,
    assignment_time timestamp,
    connector_type text,
    org_id uuid,
    user_ids text,
    PRIMARY KEY (connector_id, assignment_time));

and my query

Insert into discoveryassignment.connector_assignments(connector_id,assignment_time,connector_type,org_id,user_ids) values('f1b987df-2dfbd-437b-bda8-ff459e016f86',"2020-04-24 11:07:37+0000",'migrated',584cf4cd-eea7-4c8c-83ee-67d88fc6ccc5,"[{“userId":"ca38a547-4de4-26ab-bacb-5de9e7449958","fusionType":"calendar"},{"userId":"09d8f28e-2cab-4ce0-9941-34db1de2b000","fusionType":"calendar”}]");```

Solution

  • Here is the working version of your query;

    insert into discoveryassignment.connector_assignments(connector_id, assignment_time, connector_type, org_id, user_ids)
    values ('f1b987df-2dfbd-437b-bda8-ff459e016f86', '2020-04-24 11:07:37+0000', 'migrated', 584cf4cd-eea7-4c8c-83ee-67d88fc6ccc5,
        '[{"userId":"ca38a547-4de4-26ab-bacb-5de9e7449958","fusionType":"calendar"},{"userId":"09d8f28e-2cab-4ce0-9941-34db1de2b000","fusionType":"calendar"}]');
    

    i changed assignment_time from double quotes to single ones, you had in your user_ids query - i fixed that too.

    If you are going to keep a json formatted column, i recommend you to read Cassandra collections