How to get current timestamp with CQL while using Command Line?

谁说胖子不能爱 提交于 2019-11-30 04:10:33

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()));

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).

Cassandra >= 2.2.0-rc2

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()));

In new version of cassandra could use toTimestamp(now()), and note that function dateof is deprecated.

e.g

insert into dummy(id, name, size, create_date) values (1, 'Eric', 12, toTimestamp(now()));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!