问题描述
我遇到需要更改复合主键的情况,如下所示:
旧主键:(id,source,attribute_name ,updated_at);
我想要的新主键:(source,id,attribute_name,updated_at);
我发出了以下命令(mysql like):
ALTER TABLE general_trend_table
DROP PRIMARY KEY,
ADD PRIMARY KEY(source,id,attribute_name,updated_at);
我收到以下错误:
错误请求:第1:38行在输入PRIMARY中无可行替代
任何想法如何解决此问题?更具体地说,我想知道是否有任何方法可以更改cassandra中的主键?
您可以使用新的主键创建一个新表,从旧的主键复制数据,然后删除旧表。
I'm in a situation where I need to change the the composite primary key as follows:
Old Primary Key: (id, source, attribute_name, updated_at);
New Primary Key I want: (source, id, attribute_name, updated_at);
I issued the following (mysql like) command:
ALTER TABLE general_trend_table
DROP PRIMARY KEY,
ADD PRIMARY KEY(source, id, attribute_name, updated_at);
I got the following error:
Bad Request: line 1:38 no viable alternative at input 'PRIMARY'
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.
这篇关于alter cassandra CQL 3.0中的复合主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!