CQL provides three collection types to help you with these situations: sets, lists, and maps.

Set

The set data type stores a collection of elements. The elements are unordered when stored, but are returned in sorted order. Sets can contain the simple types, as well as user-defined types and even other collections. One advantage of using set is the ability to insert additional items without having to read the contents first.

ALTER TABLE user ADD emails set<text>;

UPDATE user SET emails = { '[email protected]' } WHERE first_name = 'Alex' AND last_name = 'Won';

You can add another email address without replacing the whole set by using concatenation.

UPDATE user SET emails = emails + { '[email protected]' } WHERE first_name = 'Alex' AND last_name = 'Won';
UPDATE user SET emails = emails - { '[email protected]' } WHERE first_name = 'Alex' AND last_name = 'Won';
UPDATE user SET emails = {} WHERE first_name = 'Alex' AND last_name = 'Won';

List

The list data type contains an ordered list of elements. By default, the values are stored in order of insertion.

ALTER TABLE user ADD phone_numbers list<text>;

UPDATE user SET phone_numbers = [ '010-0000-0000' ] WHERE first_name = 'Alex' AND last_name = 'Won';

You can replace an individual item in the list when you reference it by its index.

UPDATE user SET phone_numbers[1] = '010-1111-1111' WHERE first_name = 'Alex' AND last_name = 'Won';

You can delete a specific item directly using its index.