如何在CQL3中为复合键列提供空列值

编程入门 行业动态 更新时间:2024-10-23 09:40:13
本文介绍了如何在CQL3中为复合键列提供空列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这听起来很愚蠢,因为SQL的复合主键中没有空值。但是只是想确认我们是否可以在CQL3中使用相同的代码? 因此,我们有一个像这样的表来存储宽行:

This may sound silly as there are no null values in SQL's composite primary key. But just want to confirm if we can have the same in CQL3? So, we have a table like this to store wide rows:

CREATE TABLE keyspace12.colFamily1 ( id text, colname text, colvalue blob, PRIMARY KEY (id,colname, colvalue) ) WITH COMPACT STORAGE

在某些情况下,colname为null。我可以那样做吗?如果是,那怎么办?如果为否,那么存储宽列行的方法是什么,在该行中我们可以在cassandra的复合列的第一部分中添加一些null(根据Thrift的约定)?

And we have some cases where colname is null. Can I do that? If yes, then how? If NO, then what are the ways to store wide columns rows where we can have some null in first part of composite column of cassandra(As per Thrift's convention)?

相关问题是: CQL3和数百万列复合关键用例和 Cassandra-如何使用cqlsh创建复合列名(不是键)

推荐答案

说我有一个列家庭

CREATE TABLE cnt_test (time_slot text , comp1 text, comp2 text, field1 counter, field2 counter, PRIMARY KEY(time_slot,comp1, comp2));

现在我要在其中插入一些数据

Now i am trying to insert some data in it

UPDATE cnt_test SET field1=field1+1, field2=field2+2 WHERE time_slot='20130924' AND comp1='' AND comp2='ABC'; UPDATE cnt_test SET field1=field1+1, field2=field2+2 WHERE time_slot='20130924' AND comp1='' AND comp2='ABC'; UPDATE cnt_test SET field1=field1+1, field2=field2+2 WHERE time_slot='20130924' AND comp1='' AND comp2='ABC'; UPDATE cnt_test SET field1=field1+1, field2=field2+2 WHERE time_slot='20130924' AND comp1='' AND comp2='XYZ'; UPDATE cnt_test SET field1=field1+1, field2=field2+2 WHERE time_slot='20130924' AND comp1='PQR' AND comp2='';

如上所示,我在复合键部分插入了一些空值,而不是 null ,而是放置空白字符。

As you can see in the above statements i have inserted some empty values in the compound key part, just instead of null i am putting the blank character.

我什至可以在同一查询上

I can even query on the same

SELECT * FROM cnt_test WHERE time_slot='20130924' AND comp1='' AND comp2='ABC'; time_slot | comp1 | comp2 | field1 | field2 -----------+-------+-------+--------+-------- 20130924 | | ABC | 4 | 8 (1 rows) SELECT * FROM cnt_test WHERE time_slot='20130924' AND comp1='PQR' AND comp2=''; time_slot | comp1 | comp2 | field1 | field2 -----------+-------+-------+--------+-------- 20130924 | PQR | | 1 | 2 (1 rows)

所以总结每件事只需替换空列值,空列,即''

So to summarize every thing just replace the null column value with empty column i.e ''

更多推荐

如何在CQL3中为复合键列提供空列值

本文发布于:2023-10-24 17:02:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524506.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中为   如何在   空列值

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!