Updating a collection
Updating the playlists table to insert the tags data.
Update the playlists table to insert the tags data:
UPDATE playlists SET tags = tags + {'2007'}
WHERE id = 62c36092-82a1-3a00-93d1-46196ee77204 AND song_order = 2;
UPDATE playlists SET tags = tags + {'covers'}
WHERE id = 62c36092-82a1-3a00-93d1-46196ee77204 AND song_order = 2;
UPDATE playlists SET tags = tags + {'1973'}
WHERE id = 62c36092-82a1-3a00-93d1-46196ee77204 AND song_order = 1;
UPDATE playlists SET tags = tags + {'blues'}
WHERE id = 62c36092-82a1-3a00-93d1-46196ee77204 AND song_order = 1;
UPDATE playlists SET tags = tags + {'rock'}
WHERE id = 62c36092-82a1-3a00-93d1-46196ee77204 AND song_order = 4;
A music reviews list and a schedule (map collection) of live appearances can be added to the table:
ALTER TABLE playlists ADD reviews list<text>;
ALTER TABLE playlists ADD venue map<timestamp, text>;
Each element of a set, list, or map is internally stored as one Cassandra column. To update a set, use the UPDATE command and the addition (+) operator to add an element or the subtraction (-) operator to remove an element. For example, to update a set:
UPDATE playlists
SET tags = tags + {'punk rock'}
WHERE id = 62c36092-82a1-3a00-93d1-46196ee77204 AND song_order = 4;
To update a list, a similar syntax using square brackets instead of curly brackets is used.
UPDATE playlists
SET reviews = reviews + [ 'best lyrics' ]
WHERE id = 62c36092-82a1-3a00-93d1-46196ee77204 and song_order = 4;
To update a map, use INSERT to specify the data in a map collection.
INSERT INTO playlists (id, song_order, venue)
VALUES (62c36092-82a1-3a00-93d1-46196ee77204, 4,
{ '2013-9-22 22:00' : 'The Fillmore',
'2013-10-1 21:00' : 'The Apple Barrel'});
INSERT INTO playlists (id, song_order, venue)
VALUES (62c36092-82a1-3a00-93d1-46196ee77204, 3,
{ '2014-1-22 22:00' : 'Cactus Cafe',
'2014-01-12 20:00' : 'Mohawk'});
Inserting data into the map replaces the entire map.
Selecting all the data from the playlists table at this point gives you output something like this: