2014-11-04 42 views
1

我在使用now()函数时遇到问题timestamp类型。DSE/Cassandra CQL now()不适用于时间戳记类型

请看看下面的代码:

创建表:

CREATE TABLE "Test" (
    video_id UUID, 
    upload_timestamp TIMESTAMP, 
    title VARCHAR, 
    views INT, 
    PRIMARY KEY (video_id, upload_timestamp) 
) WITH CLUSTERING ORDER BY (upload_timestamp DESC); 

有问题的INSERT查询:

INSERT INTO "Test" (video_id, upload_timestamp, title, views) 
    VALUES (uuid(), now(), 'Test', 0); 

插入查询似乎看没什么问题。然而,当我执行它,我看到以下错误:

Unable to execute CQL script on 'XXX': cannot assign result of function now (type timeuuid) to upload_timestamp (type timestamp)

我在做什么错在这里?

我使用DataStax企业4.5.2

回答

4

现在()返回一个timeuuid,而不是一个时间戳。你可以尝试dateOf(now())。请从文档中阅读以下内容:

dateOf and unixTimestampOf

The dateOf and unixTimestampOf functions take a timeuuid argument and extract the embedded timestamp. However, while the dateof function return it with the timestamp type (that most client, including cqlsh, interpret as a date), the unixTimestampOf function returns it as a bigint raw value.

+0

它解决了我的问题。非常感谢你。 – kazy 2014-11-04 12:36:34

相关问题