alter cassandra CQL 3.0中的复合主键 [英] alter composite primary key in cassandra CQL 3.0

查看:800
本文介绍了alter cassandra CQL 3.0中的复合主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到需要更改复合主键的情况,如下所示:



旧主键:(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中的复合主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆