如何将 Scylla DB 中的计数器列重置为零?

How to Reset a Counter Column in Scylla DB to Zero?

是否可以在 Scylla DB 中重置计数器列?

Cassandra中,it is not possible直接将计数器列重置为零:

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.

Scylla DB也是这样吗?

Scylla 中也有类似的行为。 我们不能将计数器值重置为 0,计数器只能递增或递减。

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)

请注意尝试直接设置值时的错误。

更多信息:

https://docs.scylladb.com/using-scylla/counters/#scylla-counters

https://docs.scylladb.com/getting-started/types/#counters

https://www.scylladb.com/2017/04/04/counters/