This is a quick one, I wanted to set the writetime of a row explicitly when I populate the database for testing purposes. We use the writetime of a column to filter them out.
It required some looking around to find out how to do this…. so I figured I write an article about it.
INSERT INTO invoices (invoice_id,amount,tax,description) VALUES ('333',10,3,'ice-cream') USING TIMESTAMP 1458134077121;
The timestamp will be set for ALL cells in this row (well not the primary key, cause it does not have a timestamp, but the others).
The timestamp is given as millisecondsÂ since EPOC, so lots of digitsÂ :-).
A prepared statement would then look like this (Scala code)
val cql = "INSERT INTO invoices (invoice_id,amount,tax,description) VALUES (?,?,?,?) USING TIMESTAMP ?;"
val stmt = session.prepare( cql )
val bs = stmt.bind()
bs.setString("invoice_id", "333" )
bs.setLong("amount", 10L )
bs.setLong("tax", 3L )
bs.setLong("[timestamp]", 1458134077121L )
val result = Â session.execute( bs )
TTL and TIMESTAMP can both be set like this, i.e. with [ttl] and [timestamp]