4

I am trying to update an existing string column in cassandra table.

For example i want to append domain id in front of username.

Following is my table

id, username
1, agaikwad
2, xyz

I want to write cql to update above table to reflect following

id, username
1, homeoffice\\agaikwad
2, homeoffice\\xyz

Following is what I have tried

update users set username = 'homeoffice\\' + username where id = <id>
Abhijit Gaikwad
  • 3,072
  • 28
  • 37

1 Answers1

5

This is not allowed in C* because it implicitly requires a read before a write which is a bad practice with C* (and an expensive proposition in a distributed system). For a similar behavior you could store this field as a list of strings, lists support the append operation and you would be able to concatenate on the application side.

RussS
  • 16,476
  • 1
  • 34
  • 62
  • 2
    It's also a good practise to have separate columns for separate things. If you want to store `office` in your table, just create a column for it. – shutty Jun 02 '15 at 05:27
  • I see @shutty We were trying to avoid that because that needs code changes in java. By doing update i could get away with Java code changes – Abhijit Gaikwad Jun 02 '15 at 17:48