【问题标题】:How to select from the Cassandra using JSON child object in a column?如何使用列中的 JSON 子对象从 Cassandra 中进行选择?
【发布时间】:2021-04-27 04:50:30
【问题描述】:

以下是 Cassandra 中条目的外观:

id | address                     | age | family  | name | siblings
-----------------------------------------------------------------
 1 | {'city': 'c1', 'rue': 'r1'} |  23 |      si |   si | {'b', 'd'}

我想select 基于address 列中 JSON 的子城市:

我不确定以下陈述是否正确:

select address from Persons address.city='f';  
select address.city from Persons ;   

【问题讨论】:

    标签: cassandra cql cqlsh


    【解决方案1】:

    很遗憾,这在 Cassandra 中无法做到(至少目前如此)。

    一种可能的选择是将模型更改为类似

     id | city | rue | age | family  | name | siblings
    ----+------+-----+-------------------------------
      1 |   c1 |  r1 |  23 |      si |   si | {'b', 'd'}
    

    然后你就可以执行查询了:

    select json city, rue from addresses where city = 'c1';  
    

    在结果中实现“即用型”json:

     [json]
    -----------------------------
    {"city": "c1", "rue": "r1"}
    

    【讨论】:

      猜你喜欢
      • 2017-09-06
      • 1970-01-01
      • 2012-05-06
      • 2011-07-22
      • 2014-04-15
      • 1970-01-01
      • 1970-01-01
      • 2018-04-30
      • 2022-12-04
      相关资源
      最近更新 更多