2014-11-04 73 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

相關問題