我们可以将主键添加到集合数据类型吗?

Can we add primary key to collection datatypes?

当我尝试使用包含关键字检索 table 时提示 "Cannot use CONTAINS relation on non collection column col1" 但是当我尝试使用

创建 table
CREATE TABLE test (id int,address map<text, int>,mail list<text>,phone set<int>,primary key (id,address,mail,phone));

提示"Invalid collection type for PRIMARY KEY component phone"

Cassandra 的基础之一是您不能修改主键。永远记住这一点。

您不能将集合用作主键,除非它被冻结,这意味着您不能修改它。

这会起作用

CREATE TABLE test (id int,address frozen<map<text, int>>,mail frozen<list<text>>,phone frozen<set<int>>,primary key (id,address,mail,phone));;

不过,我认为你应该看看这个文档:http://www.datastax.com/dev/blog/cql-in-2-1

您可以在 cql 2.1 之后为集合添加二级索引。您可能想要使用该功能。