【问题标题】:Can we add primary key to collection datatypes?我们可以为集合数据类型添加主键吗?
【发布时间】:2016-04-18 06:06:27
【问题描述】:

当我尝试使用 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"

【问题讨论】:

    标签: cassandra cassandra-2.0


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-08
      • 1970-01-01
      • 2011-09-17
      • 2017-10-06
      • 1970-01-01
      • 1970-01-01
      • 2022-06-16
      • 2019-07-01
      相关资源
      最近更新 更多