1
votes

I have some table in Cassandra, and I need to add field with default data.

Is there way, to add default value to already existing rows, without updating all data manually?

 ALTER TABLE data ADD some_bool bool;  // Make it false for all existing records.

(Docs: ALTER TABLE Does not update existing rows)

1
If you add new column, existing data don't have that column's value. So if you get the value of that column you will get null. But for boolean type you will get false and int, bigint you will get 0, If you are using Java Driver - Ashraful Islam

1 Answers

2
votes

You have to take care of that at application level when you retrieve the rows. Cassandra will return data to the client as NULL, so everything depends on the driver and language you use. Check the driver's documentation to find out if the returned values are null or real values. They usually have an isNull method to perform such checks.