cassandra - DSE/Cassandra CQL now() 不适用于时间戳类型

标签 cassandra cql datastax-enterprise

我在使用 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/

相关文章:

database-design - Cassandra 中的用户信息存储

php - 相关标签算法

cassandra - 是否可以在 cql 脚本中的 cql 命令中使用变量?

java - Cassandra java驱动程序连接错误

java - 由于 Cassandra 没有事务并且所有语句都是原子的,因此如果需要,如何模拟回滚?

java - 您可以使用 session.execute 从 Datastax 驱动程序执行创建表吗?

c# - Cassandra C# insert 似乎正在删除先前的数据?

java - Cassandra 错误: Column timestamp is required

hadoop - 如何更改 Hive 元存储的位置?

cassandra - 如何更新 Cassandra 集群的配置