我在使用 now()
函数和 timestamp
类型时遇到问题。
请看下面的代码:
表创建:
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);
INSERT 查询对我来说看起来不错。但是,当我执行它时,我看到以下错误:
无法在“XXX”上执行 CQL 脚本:现在无法将函数结果(类型 timeuuid)分配给 upload_timestamp(类型时间戳)
我在这里做错了什么?
我使用 DataStax Enterprise 4.5.2
最佳答案
now() 返回一个 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.
关于cassandra - DSE/Cassandra CQL now() 不适用于时间戳类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26734999/