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

时间:2016-04-18 06:06:28

标签: 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));

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

1 个答案:

答案 0 :(得分:4)

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之后将二级索引放在集合上。您可能想要使用该功能。

相关问题