按创建日期排序在Cassandra中

Hamet Gholizadeh

我在cassandra 数据库中订购数据时遇到问题这是我的表结构:

CREATE TABLE posts (
    id uuid,
    created_at timestamp,
    comment_enabled boolean,
    content text,
    enabled boolean,
    meta map<text, text>,
    post_type tinyint,
    summary text,
    title text,
    updated_at timestamp,
    url text,
    user_id uuid,
    PRIMARY KEY (id, created_at)
) WITH CLUSTERING ORDER BY (created_at DESC)

当我运行此查询,我得到了以下信息:

查询

 select * from posts order by created_at desc;

讯息

ORDER BY is only supported when the partition key is restricted by an EQ or an IN.

或者此查询返回数据而不进行排序:

select * from posts
圣诞79

该错误信息是很清楚的:你不能ORDER BY没有限制与查询WHERE子句。这是设计使然。

没有运行时,你得到的数据WHERE实际上子句有序的,不是你的聚集键,而是通过将令牌功能,以您的分区键。您可以通过发出确认的顺序:

SELECT token(id), id, created_at, user_id FROM posts;

其中,token函数参数完全符合您的分区键

我建议你阅读理解你可以/不可以做什么。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章