Dive into Update vs. Insert Commands in Cassandra

You Don’t Know Cassandra

Yifeng Liu
4 min readNov 2, 2023

Cassandra beginners often learn the Insert and Update commands from DataStax CQL documentation — DataStax CQL Commands. However, the examples provided within are quite simple, and a lot of details are omitted. As a result, they tend to assume that Insert and Update commands are identical.

Even the popular book, Cassandra: The Definitive Guide, Chapter 4, The Cassandra Query Language, presents similar information stating that Insert and Update Commands are treated almost the same.

INSERT, UPDATE, AND UPSERT

Because Cassandra uses an append model, there is no fundamental difference between the insert and update operations. If you insert a row that has the same primary key as an existing row, the row is replaced. If you update a row and the primary key does not exist, Cassandra creates it.

In this post, we will delve into the following topics:

  1. An example that illustrates why Insert and Update commands should not be used interchangeably, as doing so can lead to erratic behavior.
  2. A deep dive into Insert and Update commands, highlighting three key takeaways

Example

Data model is very simple. All of examples were run at Cassandra 4.1.3 & CQL spec 3.4.6

CREATE TABLE experiment ( id text PRIMARY KEY, info text);

--

--