Reputation: 45
We're trying to setup an INSERT statement on a table with a set<text> column data type in Cassandra, but have come up with no luck. Here's an example:
INSERT INTO test_table
(my_items)
VALUES
([{"test1":"test val 1","test2":"test val 2"}])
The result is always something like:
no viable alternative at input for [test val ]2
Upvotes: 0
Views: 11124
Reputation: 12830
Enclosing values in curly brackets and separate by comma
Example :
Let's we have the schema :
CREATE TABLE users (
user_id text PRIMARY KEY,
first_name text,
last_name text,
emails set<text>
);
Insert :
INSERT INTO users (user_id, first_name, last_name, emails)
VALUES('frodo', 'Frodo', 'Baggins', {'[email protected]', '[email protected]'});
Update :
UPDATE users SET emails = emails + {'[email protected]'}
WHERE user_id = 'frodo';
More Using the set type
Edited
If you want to insert value "test1":"test val 1"
and "test2":"test val 2"
into set then enclose each value with single quote
Example :
INSERT INTO users (user_id, first_name, last_name, emails)
VALUES('2011331035', 'Md Ashraful', 'Islam', {'"test1":"test val 1"', '"test2":"test val 2"'});
Upvotes: 3