【问题标题】:Cassandra CQL where clause parenthesesCassandra CQL where 子句括号
【发布时间】:2017-01-01 19:22:07
【问题描述】:

拥有这个实体

@Table(keyspace = KEYSPACE)
public class CE_TimeSeries extends Entity implements TimeSeriesPoint{

    @PartitionKey(1)
    private String typeId;
    @ClusteringColumn(value=1, asc=true)
    private String userId;
    @ClusteringColumn(value=2, asc=true)
    private Date startDate;  
    @Column
    private Date endDate;  
    @Column
    private int groupInterval;
    @Column
    private int interval;
}

这个 CQL

SELECT startDate, endDate, groupInterval, interval FROM CE_TimeSeries WHERE typeId 
= :typeId and userId = :userId and ( endDate >= :fromDate or  ( startDate >= 
:fromDate and   startDate <= :toDate ) )

给出例外:

Caused by: com.datastax.driver.core.exceptions.SyntaxError: line 1:142 
mismatched input 'or' expecting ')' (... ( endDate >= :fromDate [or]  (...)

【问题讨论】:

    标签: cassandra datastax cql


    【解决方案1】:

    虽然我在这里实际上没有看到任何问题,但我假设您想知道为什么会出现异常。您的查询有两个问题。

    1. CQL 不允许在 WHERE 子句中使用 OR
    2. CQL 不允许在 WHERE 子句中使用括号。另外,没有OR 可用的类型排除了对parens 的需要。

    归根结底,CQL 不是 SQL,您可以在 WHERE 子句中应用的逻辑很大程度上取决于存储模型。

    【讨论】:

    • 没有 OR 怎么办?!
    • @NassimMOUALEK 构建不依赖于其使用的查询模型。
    猜你喜欢
    • 2018-09-19
    • 2016-06-12
    • 1970-01-01
    • 2015-09-13
    • 2016-12-14
    • 2020-02-08
    • 2013-04-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多