【问题标题】:Cassandra 1.2 removing an item from a list column and removing the row when the list is emptyCassandra 1.2 从列表列中删除一个项目并在列表为空时删除该行
【发布时间】:2013-05-05 17:39:06
【问题描述】:

我有一个 Cassandra 1.2 列族,如下所示:

food: 'steak'
value: 10
desserts: ['chocolate cake','banana pie','strawberry icecream']

我需要从这一行中删除一个甜点,例如“巧克力蛋糕”,但是如果在删除我需要删除整行的其中一个项目后甜点列表导致一个空列表,有没有办法在 Cassandra 的单个查询中实现这一点?如果没有,最好的方法是什么?

更多信息:我用来删除列表中的一项的查询是这样的:

update Table
set desserts = desserts - ['chocolate cake']
where food = 'steak'

提前致谢!

【问题讨论】:

    标签: cassandra


    【解决方案1】:

    cassandra 尚不支持 Collection 框架上的这种高级功能。现在我猜你必须执行两个查询才能完成操作。

    【讨论】:

      【解决方案2】:

      从列表中删除元素的一行语句:

      DELETE desserts[1] FROM table WHERE where food = 'steak';
      

      供参考, 来自datastax的以下链接中的第6点: http://docs.datastax.com/en/cql/3.0/cql/cql_using/use_list_t.html

      此链接详细讨论了 cassandra 中使用的列表类型。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-12-20
        • 1970-01-01
        • 2011-01-17
        • 1970-01-01
        • 1970-01-01
        • 2015-04-02
        • 2011-02-14
        相关资源
        最近更新 更多