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.
1 |
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)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
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.setString("description","ice-cream") bs.setLong("[timestamp]", 1458134077121L ) val result = Â session.execute( bs ) |
TTL and TIMESTAMP can both be set like this, i.e. with [ttl] and [timestamp]
-Tobias