如何在使用命令行时使用CQL获取当前时间戳? [英] How to get current timestamp with CQL while using Command Line?
问题描述
我试图从命令行插入我的CQL表。我能够插入一切。但我想知道如果我有一个时间戳列,然后如何插入到时间戳列从命令行?基本上,我想插入当前时间戳每当我插入到我的CQL表 -
I am trying to insert into my CQL table from the command line. I am able to insert everything. But I am wondering if I have a timestamp column, then how can I insert into timestamp column from the command line? Basically, I want to insert current timestamp whenever I am inserting into my CQL table -
目前,我是硬编码的时间戳,每当我插入到我的下面的CQL表 - / p>
Currently, I am hardcoding the timestamp whenever I am inserting into my below CQL table -
CREATE TABLE TEST (ID TEXT, NAME TEXT, VALUE TEXT, LAST_MODIFIED_DATE TIMESTAMP, PRIMARY KEY (ID));
INSERT INTO TEST (ID, NAME, VALUE, LAST_MODIFIED_DATE) VALUES ('1', 'elephant', 'SOME_VALUE', 1382655211694);
有什么方法可以使用CQL中的某些预定义函数获取当前时间戳,表,我可以使用该方法获取当前时间戳,然后插入到上表中。
Is there any way to get the current timestamp using some predefined functions in CQL so that while inserting into above table, I can use that method to get the current timestamp and then insert into above table?
推荐答案
可以使用timeuuid函数 now()
和 dateof()
(或更高版本的Cassandra, toTimestamp
),例如
You can use the timeuuid functions now()
and dateof()
(or in later versions of Cassandra, toTimestamp()
), e.g.,
INSERT INTO TEST (ID, NAME, VALUE, LAST_MODIFIED_DATE)
VALUES ('2', 'elephant', 'SOME_VALUE', dateof(now()));
now
函数没有参数,一个新的唯一timeuuid(在使用它的语句被执行的时候)。 dateOf
函数接受一个timeuuid参数,并提取嵌入的时间戳。 (取自时间函数的CQL文档)。
The now
function takes no arguments and generates a new unique timeuuid (at the time where the statement using it is executed). The dateOf
function takes a timeuuid argument and extracts the embedded timestamp. (Taken from the CQL documentation on timeuuid functions).
dateof()
已在Cassandra 2.2中弃用.0-rc2。对于更高版本,您应该用 toTimestamp()
替换其使用,如下所示:
dateof()
was deprecated in Cassandra 2.2.0-rc2. For later versions you should replace its use with toTimestamp()
, as follows:
INSERT INTO TEST (ID, NAME, VALUE, LAST_MODIFIED_DATE)
VALUES ('2', 'elephant', 'SOME_VALUE', toTimestamp(now()));
这篇关于如何在使用命令行时使用CQL获取当前时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!