Database Reference
In-Depth Information
Observe that cqlsh outputs the value of a set column using the same set literal we en-
countered previously, and that our update of the column worked as intended.
Advanced set manipulation
This access pattern is quite familiar, and we can anticipate that it's just as vulnerable to
data loss as the serialized approach we explored previously. The beauty of a collection
column is that, if we want to add a value to the set, we can write a CQL statement to do
just that. Let's pick up our scenario with the addition of carol 's star to alice 's status
update:
UPDATE "user_status_updates"
SET "starred_by_users" = "starred_by_users" + {'carol'}
WHERE "username" = 'alice'
AND "id" = 76e7a4d0-e796-11e3-90ce-5f98e903bf02;
Note that, in the above statement, the previous value of the starred_by_users
column does not appear; in fact, during the entire operation, there is no need for us to read
data from the row at all. The SET clause in our UPDATE statement simply instructs Cas-
sandra to set starred_by_users to the union of its current value and the one-element
set containing 'carol' ; or, put more simply, to add 'carol' to the existing set.
Let's check the value of the set after our update:
As we instructed, the set now contains both 'bob' and 'carol' , putting it in the exact
state we would expect. In similar fashion, we can now add 'dave' to the list:
Search WWH ::




Custom Search