Timestamp in Insert Into Command

1,161 views
Skip to first unread message

Paul Palumbo

unread,
Sep 6, 2013, 1:37:54 PM9/6/13
to java-dri...@lists.datastax.com
How do I create an Insert Command with a Date/Time field?
 
I'm doing the following:

    QueryBuilder.insertInto("datatable").value("id", id).value("datetime", datetime);

where datatime is of Java "Date" type. 

This seems to get translated to:

  INSERT INTO datatable (id, datetime) VALUES (1, 635140710777125909);

 

But, when I do a SELECT on the data in CQL Shell, I'm getting:

Failed to format value 635140710777125.9 as timestamp: (22, 'Invalid argument')

The "DateTime" field is defined as a "timestamp" in the CREATE TABLE command.

So, what is the proper way to insert a timestamp (Date and Time) into a Cassandra table using the Datastax Java Client?

 

Joaquin Casares

unread,
Sep 6, 2013, 3:27:33 PM9/6/13
to java-dri...@lists.datastax.com
Hello Paul,

Could you try selecting on a Long value instead?

Also, the timestamp you're selecting on is 3 orders of magnitude off from what you inserted.

Cheers,

Joaquin Casares
DataStax
Software Engineer in Test


To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.

Sylvain Lebresne

unread,
Sep 10, 2013, 10:27:57 AM9/10/13
to java-dri...@lists.datastax.com
It would be helpful to know which version of Cassandra/cqlsh and the driver your are using, as well as maybe a small example that reproduce this.
Because I can't reproduce what you are seeing on the current Cassandra 1.2 with cqlsh: inserting the query above followed by a select works correctly.
That being said, the timestamp that you show in your example above is definitively weird: it's way too big to correspond to a meaningful date. And since the driver really just use Date.getTime(), you may want to have a look at how you create your Date object in the first place.

--
Sylvain


To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.

Reply all
Reply to author
Forward
0 new messages