Cassandra: Adding new column to the table

Viewed 6736

Hi I just added a new column Business_sys to my table my_table:

   ALTER TABLE my_table ALTER business_sys TYPE set<text>;

But again I just droped this column name because I wanted to change the type of column:

  ALTER TABLE my_table DROP business_sys;

Again when I tried to add the same colmn name with different type am getting error message

"Cannnot add a collection with the name business_sys because the collection with the same name and different type has already been used in past"

I just tried to execute this command to add a new column with different type-

  ALTER TABLE my_table ADD business_sys list<text>;

What did I do wrong? I am pretty new to Cassandra. Any suggestions?

2 Answers

EDIT: I've tried this out in Cassandra and ended up with inconsistent missing data. Best way to proceed is to change the column name as suggested in CASSANDRA-6276. And always follow documentation guidelines :)

-WARNING- According to this comment from CASSANDRA-6276, running the following workaround is unsafe.

Elaborating on @masum's comment - it's possible to work around the limitation by first recreating the column with a non-collection type such as an int. Afterwards, you can drop and recreate again using the new collection type.

From your example, assuming we have a business_sys set:

ALTER TABLE my_table ADD business_sys set<text>;
ALTER TABLE my_table DROP business_sys;

Now re-add the column as int and drop it again:

ALTER TABLE my_table ADD business_sys int;
ALTER TABLE my_table DROP business_sys;

Finally, you can re-create the column with the same name but different collection type:

ALTER TABLE my_table ADD business_sys list<text>;
Related