Was this page helpful?
You're viewing documentation for an unstable version of ScyllaDB Enterprise. Switch to the latest stable version.
Updating a row is done using an
update_statement: UPDATE `table_name` : [ USING `update_parameter` ( AND `update_parameter` )* ] : SET `assignment` ( ',' `assignment` )* : WHERE `where_clause` : [ IF ( EXISTS | `condition` ( AND `condition` )*) ] update_parameter: ( TIMESTAMP `int_value` | TTL `int_value` | TIMEOUT `duration` ) int_value: ( `integer` | `bind_marker` ) assignment: `simple_selection` '=' `term` : | `column_name` '=' `column_name` ( '+' | '-' ) `term` : | `column_name` '=' `list_literal` '+' `column_name` simple_selection: `column_name` : | `column_name` '[' `term` ']' : | `column_name` '.' `field_name` condition: `simple_selection` `operator` `term`
UPDATE NerdMovies USING TTL 400 SET director = 'Joss Whedon', main_actor = 'Nathan Fillion', year = 2005 WHERE movie = 'Serenity'; UPDATE UserActions SET total = total + 2 WHERE user = B70DE1D0-9908-4AE3-BE34-5573E5B09F14 AND action = 'click';
UPDATE statement writes one or more columns for a given row in a table. The
where_clause is used to
select the row to update and must include all columns composing the
PRIMARY KEY. Non-primary key columns are then
set using the
Note that unlike in SQL,
UPDATE does not check the prior existence of the row by default,
(except through IF, see below):
the row is created if none existed before, and updated otherwise. Furthermore, there is no way to know whether creation or update occurred.
UPDATE statement, all updates within the same partition key are applied atomically,
meaning either all provided values are stored or none at all.
UPDATE statement happening concurrently at different
cluster nodes proceed without coordination. Cell values
supplied by a statement with the highest timestamp will prevail.
UPDATE statements or
statements have the same timestamp, a conflict resolution algorithm determines which cells prevails
(see update ordering).
c = c + 3 is used to increment/decrement counters. The column name after the ‘=’ sign must be the same as
the one before the ‘=’ sign. Note that increment/decrement is only allowed on counters, and are the only update
operations allowed on counters. See the section on counters for details.
id = id + <some-collection> and
id[value1] = value2 are for collections, see the relevant section for details.
id.field = 3 is for setting the value of a field on non-frozen user-defined types.
Please refer to the update parameters section for more information on the
It is, however, possible to use the conditions on some columns through
IF, in which case the row will not be updated
unless the conditions are met. Each such
UPDATE gets a globally unique timestamp.
But, please note that using
IF conditions will incur a non-negligible performance
cost (internally, Paxos will be used), so this should be used sparingly.
© 2016, The Apache Software Foundation.
Apache®, Apache Cassandra®, Cassandra®, the Apache feather logo and the Apache Cassandra® Eye logo are either registered trademarks or trademarks of the Apache Software Foundation in the United States and/or other countries. No endorsement by The Apache Software Foundation is implied by the use of these marks.