更新为空集

Updating to empty set

我刚刚为 table

创建了一个新专栏
alter table user add (questions set<timeuuid>);

现在 table 看起来像

user (
    google_id text PRIMARY KEY,
    date_of_birth timestamp,
    display_name text,
    joined timestamp,
    last_seen timestamp,
    points int,
    questions set<timeuuid>
)

然后我尝试将所有这些空值更新为空集,方法是

update user set questions = {} where google_id = ?;

每个 google id。

然而它们仍然是空的。

如何用空集填充该列?

A set, list, or map needs to have at least one element because an empty set, list, or map is stored as a null set.

source

此外,如果您使用的是客户端(例如 java), 可能会有所帮助。

我了解到实际上并没有空集或列表等东西

这些在 cqlsh 中显示为 null

但是,您仍然可以向它们添加元素,例如

> select * from id_set;
 set_id                | set_content
-----------------------+---------------------------------
 104649882895086167215 | null
 105781005288147046623 | null

> update id_set set set_content = set_content + {'apple','orange'} where set_id = '105781005288147046623';
 set_id                | set_content
-----------------------+---------------------------------
 104649882895086167215 | null
 105781005288147046623 | { 'apple', 'orange' }

因此,即使它显示为 null,您也可以认为它已经包含空集。