Reputation: 843
I want to declare specific field from user-defined type as primary key. Assume I have this :
CREATE TYPE entity (
entity_id TEXT,
entity_type TEXT
);
CREATE TABLE some_object_by_entity_id (
someId TEXT,
mytext TEXT,
entity FROZEN<entity>,
PRIMARY KEY ((entity.entity_id), transaction_id)
) WITH CLUSTERING ORDER BY (transaction_id ASC);
...
now I want to make somehow the entity_id from entity (which is a user-defined type) to be my primary key, but Cassandra gives me syntax error. Am I able to do so with any other syntax ?
Upvotes: 2
Views: 472
Reputation: 8812
You can't do that, try to duplicate the entity_id as a simple column of your table:
CREATE TABLE some_object_by_entity_id (
entity_id TEXT,
someId TEXT,
mytext TEXT,
entity FROZEN<entity>,
PRIMARY KEY ((entity_id), transaction_id)
) WITH CLUSTERING ORDER BY (transaction_id ASC);
The drawback of this solution is you need to keep in sync your table entity_id and the entity_id value inside the frozen entity manually from the application code.
Upvotes: 3