从地图中选择特定值 [英] SELECT Specific Value from map
本文介绍了从地图中选择特定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个宽列表,20,000 多列
I am trying to create a WIDE Column Table, 20,000+ columns
最初我想我会使用:
CREATE TABLE details (
key TEXT,
detail map<TEXT, TEXT>
PRIMARY KEY (KEY)
);
插入此表工作正常
UPDATE details SET detail = detail + { 'col1': '12'} where key='123' ;
UPDATE details SET detail = detail + { 'col20000': 'ABCD'} where key='123' ;
但是,我想阅读一个单独的细节:
However, I would like to read an individual detail:
select detail[col1] where key='123'
执行此查询时出现以下错误:
when executing this query I get the following error:
no viable alternative at input '['
这行得通,还是我需要不同的方法?
Will this work, or do I need a different approach?
推荐答案
集合是您一次性获取的一小组数据.
Collections are small groups of data that you fetch all at once.
如果您想在更精细的级别访问元组,并且仍然能够询问给定键的所有数据对是什么",您应该使用这样的表:
If you want to access tuples at a finer level, and still be able to ask "what are all the pairs of data for a given key," you should use a table like this:
CREATE TABLE details (
key TEXT,
detail_key text,
detail_value text,
PRIMARY KEY (key, detail_key)
);
这将允许 SELECT * FROM details WHERE key = ?
以及 SELECT * FROM detail WHERE key = ?AND detail_key = ?
.
这篇关于从地图中选择特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文