Does updating a row in a Cassandra table also change the write time?

Viewed 472

I have a table in Cassandra which gets updated all the time. I wanted to know, if the write time of a row / value gets updated with each update to the data in the row or if there is only one write time (timestamp) given when i first write to the table that never changes. Thanks to anyone who can answer :)

2 Answers

Here is an example showing that the timestamp changes only on the column updated:

cqlsh:keyspace1> create table keyspace1.testwrites (id int primary key, firstname text, lastname text);
cqlsh:keyspace1> insert into testwrites(id, firstname, lastname) values (1, 'Valerie', 'Rodriguez');
cqlsh:keyspace1> select id, firstname, writetime(firstname), lastname, writetime(lastname) from testwrites;

 id | firstname | writetime(firstname) | lastname  | writetime(lastname)
----+-----------+----------------------+-----------+---------------------
  1 |   Valerie |     1561471068014970 | Rodriguez |    1561471068014970

(1 rows)
cqlsh:keyspace1> insert into testwrites(id, firstname, lastname) values (2, 'Valerie', 'Smith');
cqlsh:keyspace1> select id, firstname, writetime(firstname), lastname, writetime(lastname) from testwrites;

 id | firstname | writetime(firstname) | lastname  | writetime(lastname)
----+-----------+----------------------+-----------+---------------------
  1 |   Valerie |     1561471068014970 | Rodriguez |    1561471068014970
  2 |   Valerie |     1561471078606684 |     Smith |    1561471078606684

(2 rows)
cqlsh:keyspace1> insert into testwrites(id, firstname, lastname) values (2, 'Valerie', 'Jones');
cqlsh:keyspace1> select id, firstname, writetime(firstname), lastname, writetime(lastname) from testwrites;

 id | firstname | writetime(firstname) | lastname  | writetime(lastname)
----+-----------+----------------------+-----------+---------------------
  1 |   Valerie |     1561471068014970 | Rodriguez |    1561471068014970
  2 |   Valerie |     1561471097668583 |     Jones |    1561471097668583

(2 rows)
cqlsh:keyspace1> insert into testwrites(id, firstname, lastname) values (3, 'Valerie', 'Garcia');
cqlsh:keyspace1> select id, firstname, writetime(firstname), lastname, writetime(lastname) from testwrites;

 id | firstname | writetime(firstname) | lastname  | writetime(lastname)
----+-----------+----------------------+-----------+---------------------
  1 |   Valerie |     1561471068014970 | Rodriguez |    1561471068014970
  2 |   Valerie |     1561471097668583 |     Jones |    1561471097668583
  3 |   Valerie |     1561471114925083 |    Garcia |    1561471114925083

(3 rows)
cqlsh:keyspace1> update testwrites set firstname='Alex' where id=1;
cqlsh:keyspace1> select id, firstname, writetime(firstname), lastname, writetime(lastname) from testwrites;

 id | firstname | writetime(firstname) | lastname  | writetime(lastname)
----+-----------+----------------------+-----------+---------------------
  1 |      Alex |     1561471131764488 | Rodriguez |    1561471068014970
  2 |   Valerie |     1561471097668583 |     Jones |    1561471097668583
  3 |   Valerie |     1561471114925083 |    Garcia |    1561471114925083

Since the data is written at each update, write time will update with each update as well.

Also, write time is for a column, WRITETIME function also takes the column to retrieve the timestamp.

Refer to documentation here

Related