Almog Bentz
Almog Bentz

Reputation: 31

Insert an element into specific location in list using cassandra

I want to insert an element into a list in a specific position. I don't want to replace the previous element but rather push everything forward. Is there a way to do this natively in the cassandra or must I take the list out and rewrite it? thank you.

from the datastax documentation:
Add an element at a particular position using the list index position in square brackets

UPDATE users SET top_places[2] = 'riddermark' WHERE user_id = 'frodo';

When you add an element at a particular position, Cassandra reads the entire list, and then writes only the updated element. Consequently, adding an element at a particular position results in greater latency than appending or prefixing an element to a list.

Upvotes: 2

Views: 218

Answers (1)

doanduyhai
doanduyhai

Reputation: 8812

I don't want to replace the previous element but rather push everything forward

You can't do that, you need to read and rewrite the entire list

Upvotes: 3

Related Questions