Database Reference
In-Depth Information
'washingtondc';
cqlsh:mastering_cassandra> UPDATE demo_counter_cols SET
count_users = count_users + 1, count_page_views =
count_page_views + 0 WHERE city_name = 'baltimore';
cqlsh:mastering_cassandra> SELECT * FROM demo_counter_cols;
city_name | count_page_views | count_users
--------------+------------------+-------------
washingtondc | null | 13
baltimore | 0 | 1
newyork | 42 | 1
(3 rows)
cqlsh:mastering_cassandra> UPDATE demo_counter_cols SET
count_page_views = count_page_views - 22 WHERE city_name =
'newyork';
cqlsh:mastering_cassandra> SELECT * FROM demo_counter_cols;
city_name | count_page_views | count_users
--------------+------------------+-------------
washingtondc | null | 13
baltimore | 0 | 1
newyork | 20 | 1
(3 rows)
A couple of things to notice here. First, instead of using the
INSERT
statement, we have
used the
UPDATE
statement to insert the data. If you try to insert, it will fail with an error
saying,
Bad Request: INSERT statement are not allowed on
counter tables, use UPDATE instead
. Second, an uninitiated column is set
to
null
by default. You can initiate to any value just by passing an appropriate value in
the
UPDATE
statement.