Cassandra Timestamp data type

随声附和 提交于 2020-01-05 07:49:12

问题


This is my Database Structure

CREATE TABLE stack (
    id UUID,
    entrytime TIMESTAMP,
    name TEXT,
    PRIMARY KEY (id, entrytime)
) WITH CLUSTERING ORDER BY ( entrytime DESC );

And when I use the Insert statement as.

INSERT INTO stack ( id, entrytime, name )
VALUES ( now(), toTimestamp( now() ), 'Nik' );

But it stores the entry time column as 2018-01-15 08:29:58.174000+0000

I want to remove the extra precision that Cassandra provides. I know this has to do something with the cqlshrc.sample file but I am not able to do it.

Can anyone help me out here?

This is a portion of my cqlshrc file

[ui]
;; Whether or not to display query results with colors
; color = on

;; Used for displaying timestamps (and reading them with COPY)
time_format = %Y-%m-%d %H:%M:%S

;; Display timezone
;timezone = Etc/UTC

Now when I run my cql shell then following error occurs.

  Traceback (most recent call last):
    File "/var/www/html/cassandra/apache-cassandra-
   3.11.1/bin/cqlsh.py", line 2434, in <module>
     main(*read_options(sys.argv[1:], os.environ))
   File "/var/www/html/cassandra/apache-cassandra-
   3.11.1/bin/cqlsh.py", line 2211, in read_options
     configs.read(CONFIG_FILE)
   File "/usr/lib/python2.7/ConfigParser.py", line 305, in read
     self._read(fp, filename)
   File "/usr/lib/python2.7/ConfigParser.py", line 512, in _read
      raise MissingSectionHeaderError(fpname, lineno, line)
   ConfigParser.MissingSectionHeaderError: File contains no section headers.
    file: /home/ubuntu/.cassandra/cqlshrc, line: 1

'\xef\xbb\xbf; Licensed to the Apache Software Foundation (ASF) under one\n'


回答1:


Just insert into ~/.cassandra/cqlshrc file, into [ui] section following line (this is for 3.x):

time_format = %Y-%m-%d %H:%M:%S%z

Description of % fields you can find here.

P.S. I've modified the answer because the datetimeformat is used only in COPY FROM's options, not in the cqlshrc...



来源:https://stackoverflow.com/questions/48276297/cassandra-timestamp-data-type

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!