cql - Cassandra UPDATE primary key value -
i understand not possible using update.
what instead, migrate rows pk=0 new rows pk=1. there simple ways of achieving this?
for relatively simple way, quick copy
to/from in cqlsh.
let's have column family (table) called "emp" employees.
create table stackoverflow.emp ( id int primary key, fname text, lname text, role text )
and purposes of example, have 1 row in it.
aploetz@cqlsh:stackoverflow> select * emp; id | fname | lname | role ----+-------+-------+------------- 1 | angel | pay | engineer
if want re-create angel new id, can copy
table's contents to
.csv file:
aploetz@cqlsh:stackoverflow> copy stackoverflow.emp '/home/aploetz/emp.csv'; 1 rows exported in 0.036 seconds.
now, i'll use favorite editor change id of angel 2 in emp.csv. note, if have multiple rows in file (that don't need updated) opportunity remove them:
2,angel,pay,it engineer
i'll save file, , copy
updated row cassandra from
file:
aploetz@cqlsh:stackoverflow> copy stackoverflow.emp '/home/aploetz/emp.csv'; 1 rows imported in 0.038 seconds.
now angel has 2 rows in "emp" table.
aploetz@cqlsh:stackoverflow> select * emp; id | fname | lname | role ----+-------+-------+------------- 1 | angel | pay | engineer 2 | angel | pay | engineer (2 rows)
for more information, check datastax doc on copy.
Comments
Post a Comment