Skip to content

Instantly share code, notes, and snippets.

@thinkerbot
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkerbot/229101ba74f7dff0c163 to your computer and use it in GitHub Desktop.
Save thinkerbot/229101ba74f7dff0c163 to your computer and use it in GitHub Desktop.

Note: cqlsh converts timestamps into current timezone

You can prove this manually:

$ cqlsh
cqlsh> CREATE KEYSPACE mykeyspace WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
cqlsh> use mykeyspace;
cqlsh> CREATE TABLE objects (id int PRIMARY KEY, name text, date timestamp);
cqlsh> INSERT INTO objects (id, name, date) VALUES (1, 'one', '2010-01-01T00:00:00Z');
cqlsh> SELECT * FROM objects;

 id | date                     | name
----+--------------------------+------
  1 | 2009-12-31 17:00:00-0700 |  one

Workaround:

$ TZ=UTC cqlsh
cqlsh> use mykeyspace;
cqlsh:mykeyspace> SELECT * FROM objects;

 id | date                     | name
----+--------------------------+------
  1 | 2010-01-01 00:00:00+0000 |  one

You can change the format (not the TZ, AFAIK) in the ~/.cassandra/cqlshrc file like this:

$ mkdir -p ~/.cassandra
$ cat > ~/.cassandra/cqlshrc <<DOC
[ui]
time_format=...%Y-%m-%d.%H:%M:%S...
DOC
$ cqlsh
cqlsh> use mykeyspace;
cqlsh:mykeyspace> SELECT * FROM objects;

 id | date                      | name
----+---------------------------+------
  1 | ...2009-12-31.17:00:00... |  one

Fun fact: if you make a ~/.cqlshrc file and change some settings as above then the next time you run cqlsh those configs will be loaded and then saved into ~/.cassandra/cqlshrc. This process removes ~/.cqlshrc so don't be too suprised when it has gone missing. o_O

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment