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

Cassandrait 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@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)

请注意在try 直接设置值时出现的错误.

更多信息:

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/

Database相关问答推荐

Rust 全局存储数据库连接

[mongodb],如何通过聚合获得具有许多不同字段的文档的最大值?子字段名称相同

仅对表中的一列授予更改

MongoDB和Redis有什么区别?

repeating groups是什么意思?

在 SQL Server 2008 R2 中,如何强制一列对于整个表是唯一的?

多少个外键才算太多?

MySQL JDBC Driver中cachePrepStmts和useServerPrepStmts有什么区别

将图像文件存储在 Mongo 数据库中,这是个好主意吗?

每个 Docker 容器一个或多个数据库

mySQL 复制是否具有即时数据一致性?

使用脚本语言动态数据库

如何在磁盘上布局 B-Tree 数据?

限制来自本地主机的 MySQL 连接以提高安全性

使用 PHP 和 MySQL 开发测验Web 应用程序的数据库设计

Sqlite 判断表是否为空

如何在 Google AppEngine 上实现自动增量

Cassandra - 事务支持

清空数据库是什么意思?

数据库事务是否防止竞争条件?