更改 cassandra CQL 3.0 中的复合主键 [英] alter composite primary key in cassandra CQL 3.0
问题描述
我需要按如下方式更改复合主键:
I'm in a situation where I need to change the the composite primary key as follows:
旧主键:(id, source, attribute_name, updated_at);
我想要的新主键:(source, id, attribute_name, updated_at);
我发出了以下(类似mysql)命令:
I issued the following (mysql like) command:
ALTER TABLE general_trend_table
DROP PRIMARY KEY,
ADD PRIMARY KEY(source, id, attribute_name, updated_at);
我收到以下错误:
错误请求:第 1:38 行在输入PRIMARY"处没有可行的替代方案
知道如何解决这个问题吗?更具体地说,我想知道有没有办法更改 cassandra 中的主键?
any idea how to get around this problem? more specifically I want to know is there any way to change the primary key in cassandra?
推荐答案
无法更改主键,因为它定义了数据的物理存储方式.
There is no way to change a primary key, as it defines how your data is physically stored.
您可以使用新的主键创建一个新表,从旧表复制数据,然后删除旧表.
You can create a new table with the new primary key, copy data from the old one, and then drop the old table.
这篇关于更改 cassandra CQL 3.0 中的复合主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!