Writing data at a specific index

What if we want to replace the data at a specific place in the list, rather than adding it to the beginning or the end? We can perform a direct assignment to the index we want as follows:

UPDATE "user_status_updates" SET "shared_by"[1] = 'robert' WHERE "username" = 'alice' AND "id" = 76e7a4d0-e796-11e3-90ce-5f98e903bf02; 

Like array indexes in most programming languages, the index for list element assignment is zero, meaning that in the preceding query, we are setting the second element of the list.

List element assignment must reference an index that is within the list's current size. For instance, if we try to assign the fourth element in our current three-element list:

UPDATE "user_status_updates" 

Get Learning Apache Cassandra - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.