gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 15:52:18 24 4
gpt4 key购买 nike

是否可以在 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/

关于database - 如何将 Scylla DB 中的计数器列重置为零?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72178766/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com