2

I have a table in cassandra with following structure:

CREATE TABLE answers (
  Id              uuid,
  Name            text,
  Description     text,
  LastVersion     boolean,
  CreationDate    timestamp,
  EditionDate     timestamp,
  PRIMARY KEY(Id, EditionDate)
)WITH CLUSTERING ORDER BY (EditionDate DESC);

The problem is when I need to update the value of the LastVersion column to false. In this case a new line is inserted only with the values โ€‹โ€‹of the Primary Key (Id, EditionDate) + the value of the LastVersion column.

In this order:

INSERT:

insert into answers 
(id, name, description, lastversion, creationdate, editiondate)
values
(uuid(), 'Test 1', 'Description 1', true, dateof(now()), dateof(now()));

RESULT:

 id                                   | editiondate                     | creationdate                    | description   | lastversion | name
--------------------------------------+---------------------------------+---------------------------------+---------------+-------------+--------
 ac4f9ec1-8737-427c-8a63-7bdb62c93932 | 2018-08-01 19:54:51.603000+0000 | 2018-08-01 19:54:51.603000+0000 | Description 1 |        True | Test 1

UPDATE:

update answers 
set lastversion = false 
where id = ac4f9ec1-8737-427c-8a63-7bdb62c93932 
and editiondate = '2018-08-01 19:54:51';

RESULT:

 id                                   | editiondate                     | creationdate                    | description   | lastversion | name
--------------------------------------+---------------------------------+---------------------------------+---------------+-------------+--------
 ac4f9ec1-8737-427c-8a63-7bdb62c93932 | 2018-08-01 19:54:51.603000+0000 | 2018-08-01 19:54:51.603000+0000 | Description 1 |        True | Test 1
 ac4f9ec1-8737-427c-8a63-7bdb62c93932 | 2018-08-01 19:54:51.000000+0000 |                            null |          null |       False |   null

What is wrong? Actually the EditionTime field seems to be different but, I spend the same value on UPDATE query.

Igor
  • 3,573
  • 4
  • 33
  • 55
  • related: https://stackoverflow.com/questions/28547616/cassandra-cqlsh-how-to-show-microseconds-milliseconds-for-timestamp-columns/28549241#28549241 โ€“ Aaron Aug 01 '18 at 20:24

1 Answers1

3

your update is using a different value for editionDate than you inserted so your update is not finding the original row. And Cassandra updates and inserts are really upserts so a new row with the new key is being inserted.

Notice the EditionDate has millisecond precision but your update is only specifying it to the nearest second.

Brandon
  • 38,310
  • 8
  • 82
  • 87
  • yeah, the edition time need to muuuuch specific. But, I need a way to remove that whole precision, like force 'format'. โ€“ Igor Aug 02 '18 at 13:21