Is it possible to reset a counter column in Scylla DB
?
In Cassandra
, it is not possible to directly reset a counter column to zero:
There is no operation that will allow resetting the counter value. You need to read the value and decrement it using that value. Be aware that this operation might not be successful since the counter can be changed between your "reset" operations.
Is this true with Scylla DB
as well?
CodePudding user response:
There is a similar behavior in Scylla. We cannot reset a counter value to 0, counters can only be incremented or decremented.
scylla@cqlsh:ks> CREATE TABLE cf (pk int PRIMARY KEY, my_counter counter);
scylla@cqlsh:ks> UPDATE cf SET my_counter = my_counter 3 WHERE pk = 0;
scylla@cqlsh:ks> SELECT * FROM cf;
pk | my_counter
---- ------------
0 | 3
(1 rows)
scylla@cqlsh:ks> UPDATE cf SET my_counter = 0 WHERE pk = 0;
InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot set the value of counter column my_counter (counters can only be incremented/decremented, not set)"
scylla@cqlsh:ks> UPDATE cf SET my_counter = my_counter - 3 WHERE pk = 0;
scylla@cqlsh:ks> SELECT * FROM cf;
pk | my_counter
---- ------------
0 | 0
(1 rows)
Notice the error when trying to set a value directly.
More about it:
https://docs.scylladb.com/using-scylla/counters/#scylla-counters