user5505266
user5505266

Reputation: 603

Converting a list column to a set column in cassandra/DSE

While iterating on a new feature my team created a list column in our DSE database. We now want it to be a set column. I dropped the column and created it again as a set column and got this error:

ALTER TABLE sometable DROP somecolumn;
ALTER TABLE sometable ADD somecolumn set<text>;

InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot add a collection with the name integrations because a collection with the same name and a different type (list) has already been used in the past"

There isn't even any data in the column. Is there not some sort of hard delete override? We can change the name but I really don't like the idea of a name that will not work if anyone tries to use it. Do I have to remake the whole table?

Upvotes: 2

Views: 583

Answers (1)

medvekoma
medvekoma

Reputation: 1181

The best option is to add an alternate column with a different name or create a new table.

Technically it is possible to drop and recreate columns, but if you already have data in these columns on disk and in backups, it may create problems bringing nodes back online if they crash. (You cant load old data of one format into new columns with a different format)

If you really must do this, you can do the following:

ALTER TABLE sometable DROP somecolumn;
ALTER TABLE sometable ADD somecolumn int;
ALTER TABLE sometable DROP somecolumn;
ALTER TABLE sometable ADD somecolumn set<text>;

(Based on a comment in Cassandra: Adding new column to the table)

Upvotes: 2

Related Questions