Cassandra UPDATE主键值 [英] Cassandra UPDATE primary key value
问题描述
我知道这是不可能使用UPDATE。
I understand that this is not possible using an UPDATE.
我想要做的是将所有行说PK = 0到新行PK = 1。
What I would like to do instead, is migrate all rows with say PK=0 to new rows where PK=1. Are there any simple ways of achieving this?
推荐答案
对于一个相对简单的方法,你总是可以做一个快速 COPY
在cqlsh中的TO / FROM。
For a relatively simple way, you could always do a quick COPY
TO/FROM in cqlsh.
假设我有一个名为emp / p>
Let's say that I have a column family (table) called "emp" for employees.
CREATE TABLE stackoverflow.emp (
id int PRIMARY KEY,
fname text,
lname text,
role text
)
我有一行。
aploetz@cqlsh:stackoverflow> SELECT * FROM emp;
id | fname | lname | role
----+-------+-------+-------------
1 | Angel | Pay | IT Engineer
如果我想使用新的ID重新创建Angel,我可以 COPY
表格的内容 TO
a .csv文件:
If I want to re-create Angel with a new id, I can COPY
the table's contents TO
a .csv file:
aploetz@cqlsh:stackoverflow> COPY stackoverflow.emp TO '/home/aploetz/emp.csv';
1 rows exported in 0.036 seconds.
现在,我将使用我最喜欢的编辑器将emp更改为emp.csv中的2 。请注意,如果您的文件中有多行(不需要更新),则可以删除它们:
Now, I'll use my favorite editor to change the id of Angel to 2 in emp.csv. Note, that if you have multiple rows in your file (that don't need to be updated) this is your opportunity to remove them:
2,Angel,Pay,IT Engineer
我将保存文件, code> COPY 更新的行返回Cassandra FROM
文件:
I'll save the file, and then COPY
the updated row back into Cassandra FROM
the file:
aploetz@cqlsh:stackoverflow> COPY stackoverflow.emp FROM '/home/aploetz/emp.csv';
1 rows imported in 0.038 seconds.
现在Angel在emp表中有两行。
Now Angel has two rows in the "emp" table.
aploetz@cqlsh:stackoverflow> SELECT * FROM emp;
id | fname | lname | role
----+-------+-------+-------------
1 | Angel | Pay | IT Engineer
2 | Angel | Pay | IT Engineer
(2 rows)
有关详细信息, a href =http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/copy_r.html> DataStax doc COPY 。
For more information, check the DataStax doc on COPY.
这篇关于Cassandra UPDATE主键值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!