1
votes

I have a table in Cassandra say employee(id, email, role, name, password) with only id as my primary key.

I want to ...

1. Add another column (manager_id) in with a default value in it

I know that I can add a column in the table but there is no way i can provide a default value to that column through CQL. I can also not update the value for manager_id later since I need to know the id (Partition key and the values are randomly generated unique values which i don't know) to update the row. Is there any way I can achieve this?

2. Rename this table to all_employee.

I also know that its not allowed to rename a table in cassandra. So I am trying to copy the data of table(employee) to csv and copy from csv to new table (all_employee) and deleting the old table(employee). I am doing this through an automated script with cql queries in it and script works fine but will fail if it gets executed again(Which i can not restrict) since the table employee will not be there once its deleted. Essentially I am looking for "If exists" clause in COPY query which is not supported in cql. Is there any other way I can achieve the outcome?

Please note that the amount of data in the table is very small so performance in not an issue.

1

1 Answers

0
votes

For #1

I dont think cassandra support default column . You need to do that from your appliaction. Write some default value every time you insert a row.

For #2

you can check if the table exists before trying to copy from it.

SELECT your_table_name FROM system_schema.tables WHERE keyspace_name='your_keyspace_name';