Search⌘ K
AI Features

Collection Data Type: LIST

Explore the LIST collection data type in Apache Cassandra to efficiently store multiple ordered values within a single column. Learn how to create, update, add, remove, and empty LIST elements, along with understanding performance considerations compared to SET collections.

In Apache Cassandra, collections are data types that store multiple values in a single column, enabling efficient data grouping, simplifying table design, providing efficient data retrieval and atomic operations.

Storing large amounts of data in a collection is an anti-pattern.

Cassandra does not support accessing individual elements of a collection, as collections are read in their entirety. The FROZEN keyword is used to nest a collection inside another collection.

Cassandra provides the following three collection types:

  • SET

  • LIST

  • MAP

The LIST collection

Like SET, a LIST groups and stores a collection of values in the same cell. However, the values need not be unique, and a value can appear multiple times. Additionally, the order of insertion is preserved in a LIST. LIST elements are enclosed in square brackets [].

LISTs are designed to store values in a particular order, representing a many-to-many relationship with another column in the table.

The following syntax is used to create a column as a LIST:

ColumnName LIST <columnDataType>

For example, to create a LIST of collaborators, the following column definition will be included in the CREATE TABLE statement :

collaborators LIST <TEXT>
...