adonthula
adonthula

Reputation: 117

Can we add primary key to collection datatypes?

When I tried to retrieve table using contains keyword it prompts "Cannot use CONTAINS relation on non collection column col1" but when I tried to create table using

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

it prompts "Invalid collection type for PRIMARY KEY component phone"

Upvotes: 4

Views: 2842

Answers (1)

&#199;elebi Murat
&#199;elebi Murat

Reputation: 163

One of the basics in Cassandra is that you can't modify primary keys. Always keep that in mind.

You can't use a collection as primary key unless it is frozen, meaning you can't modify it.

This will work

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

However, I think you should take a look at this document: http://www.datastax.com/dev/blog/cql-in-2-1

You can put secondary indexes on collections after cql 2.1. You may want to use that functionality.

Upvotes: 5

Related Questions