更新为空集

问题描述 投票:0回答:2

我刚刚为我的表创建了一个新列

alter table user add (questions set<timeuuid>);

现在表格看起来像

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 = ?;

对于每个谷歌ID。

但是它们仍然是空的。

如何用空集填充该列?

cassandra cql cassandra-3.0
2个回答
0
投票

集合,列表或映射需要至少包含一个元素,因为空集,列表或映射存储为空集。

source

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


0
投票

我已经知道,实际上并不存在空集或列表等等。

这些在null显示为cqlsh

但是,您仍然可以向其中添加元素,例如

> 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,您也可以将其视为已包含空集。

© www.soinside.com 2019 - 2024. All rights reserved.