Reputation: 2466
What would be the easiest way to migrate an int to a bigint in Cassandra? I thought of creating a new column of type bigint and then running a script to basically set the value of that column = the value of the int column for all rows, and then dropping the original column and renaming the new column. However, I'd like to know if someone has a better alternative, because this approach just doesn't sit quite right with me.
Upvotes: 1
Views: 2326
Reputation: 762
You can ALTER
your table to store bigint in cassandra with varint
. See the example-
cassandra@cqlsh:demo> CREATE TABLE int_test (id int, name text, primary key(id));
cassandra@cqlsh:demo> SELECT * FROM int_test;
id | name
----+------
(0 rows)
cassandra@cqlsh:demo> INSERT INTO int_test (id, name) VALUES ( 215478936541111, 'abc');
cassandra@cqlsh:demo> SELECT * FROM int_test ;
id | name
---------------------+---------
215478936541111 | abc
(1 rows)
cassandra@cqlsh:demo> ALTER TABLE demo.int_test ALTER id TYPE varint;
cassandra@cqlsh:demo> INSERT INTO int_test (id, name) VALUES ( 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 'abcd');
cassandra@cqlsh:demo> SELECT * FROM int_test ;
id | name
------------------------------------------------------------------------------------------------------------------------------+---------
215478936541111 | abc
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 | abcd
(2 rows)
cassandra@cqlsh:demo>
Upvotes: 0
Reputation: 5180
You could ALTER
your table and change your int
column to a varint
type. Check the documentation about ALTER TABLE
, and the data types compatibility matrix.
The only other alternative is what you said: add a new column and populate it row by row. Dropping the first column can be entirely optional: if you don't assign values when performing insert everything will stay as it is, and new records won't consume space.
Upvotes: 1