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

ado*_*ula 4 cassandra cassandra-2.0

当我尝试使用 contains 关键字检索表"Cannot use CONTAINS relation on non collection column col1"时,它会提示但当我尝试使用创建表时

CREATE TABLE test (id int,address map<text, int>,mail list<text>,phone set<int>,primary key (id,address,mail,phone));
Run Code Online (Sandbox Code Playgroud)

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

Çel*_*rat 5

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));;
Run Code Online (Sandbox Code Playgroud)

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

您可以在 cql 2.1 之后在集合上放置二级索引。您可能想要使用该功能。