Using a list type collection

Use a list when the order of elements matter or when you need to store the same value multiple times.

A list has a form much like a set, in that a list groups and stores values. Unlike a set, the values stored in a list do not need to be unique and can be duplicated. A list stores the elements in a particular order. The elements can be inserted or retrieved according to an index value.

Use the list data type to store data that has a possible many-to-many relationship with another column. In the example below, a list called events stores all the race events on a calendar. Each year and month pairing might have several events that occurred, and the races are stored in a list. The list can be ordered so that the races appear in the order that they took place rather than alphabetical order.


Define an events list in the upcoming_calendar table within the cycling keyspace. Each event listed in the list has a <text> data type.
CREATE TABLE cycling.upcoming_calendar ( year int, month int, events list<text>, PRIMARY KEY ( year, month) );