Cassandra Timestamp数据类型 [英] Cassandra Timestamp data type
问题描述
这是我的数据库结构
CREATE TABLE stack (
id UUID,
entrytime TIMESTAMP,
name TEXT,
PRIMARY KEY (id, entrytime)
) WITH CLUSTERING ORDER BY ( entrytime DESC );
当我使用Insert语句时。
And when I use the Insert statement as.
INSERT INTO stack ( id, entrytime, name )
VALUES ( now(), toTimestamp( now() ), 'Nik' );
但是它将输入时间列存储为 2018-01-15 08: 29:58.174000 + 0000
But it stores the entry time column as 2018-01-15 08:29:58.174000+0000
我想删除Cassandra提供的额外精度。
我知道这与 cqlshrc.sample
文件有关,但是我无法做到。
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?
这是我的cqlshrc文件的一部分
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
现在当我运行cql shell时发生错误。
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;获Apache Software Foundation(ASF)许可,其使用权是$ n $
'\xef\xbb\xbf; Licensed to the Apache Software Foundation (ASF) under one\n'
推荐答案
只需插入〜 /.cassandra/cqlshrc
文件,放入以下行的 [ui]
部分(用于3.x):
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.
PS我已经修改了答案,因为 datetimeformat
仅在 COPY FROM
的选项中使用,而在 cqlshrc
...
P.S. I've modified the answer because the datetimeformat
is used only in COPY FROM
's options, not in the cqlshrc
...
这篇关于Cassandra Timestamp数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!