You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Otávio Gonçalves de Santana <ot...@gmail.com> on 2017/03/13 10:09:43 UTC

Problem when try to use Date type at Cassandra

I'm reading the types in Cassandra, and I would like to use dates, The
documentations say that I can save the time as String with the following format:
https://docs.datastax.com/en/cql/3.3/cql/cql_reference/cql_data_types_c.html
So:


                  CREATE KEYSPACE IF NOT EXISTS newKeySpace WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3};CREATE COLUMNFAMILY IF NOT EXISTS newKeySpace.history ( name text PRIMARY KEY, dataStart date, dateEnd date);
                

Not using Mixmax yet?  

And Using the QueryBuilder from DataStax Java Driver I created an insertion
query:


                  Insert insert = QueryBuilder.insertInto("newKeySpace", "history")                .value("name", "World war II")                .value("dataStart", LocalDate.of(1939, Month.SEPTEMBER, 1).toString())                .value("dateEnd", LocalDate.of(1945, Month.SEPTEMBER, 2).toString());session.execute(insert);//INSERT INTO newKeySpace.history (name,dataStart,dateEnd) VALUES ('World war II','1939-09-01','1945-09-02');session.execute(insert);
                

Not using Mixmax yet?  


That throws an exception: 
com.datastax.driver.core.exceptions.InvalidQueryException: Expected 4 byte long
for date (10)
I tried with timestamp and I had a similar error.
Otávio Gonçalves de Santana

twitter:http://twitter.com/otaviojavasite:http://about.me/otaviojava