EnergyGeek
EnergyGeek

Reputation: 271

How do you return the timestamp from Cassandra when using Python and CQL?

When running the query.

"select * from temperature_by_day"

Cassandra is returning a string '\x00\x00\x017\xa7\xea\x9e\x00' for the timestamp.

If I query from cqlsh on the server it returns the dates I've set.

I've read this post: How to retrieve the timestamp from cassandra?

It states "It's not recommended to use column Cassandra timestamps directly in client code;".

Why?

The tutorial here states to query the timestamp directly.

http://planetcassandra.org/blog/post/getting-started-with-time-series-data-modeling/

So is the proper thing to do to add an additional timestamp that is not part of the primary key and query against this timestamp?

Thanks in advance.

Upvotes: 2

Views: 1122

Answers (1)

Alex Popescu
Alex Popescu

Reputation: 4012

The Datastax Python driver supports the timestamp type. If you want to learn how to deserialize it check out the DataType.deserialize method:

return datetime.utcfromtimestamp(int64_unpack(byts) / 1000.0)

Upvotes: 2

Related Questions