从映射中选择特定值 [英] SELECT Specific Value from map
问题描述
我正在尝试创建一个WIDE列表,共有2万多列
最初我想我会使用:
CREATE TABLE详细信息(
key TEXT,
详细地图< TEXT,TEXT>
PRIMARY KEY(KEY)
);
插入此表格工作正常
UPDATE details SET detail = detail + {'col1':'12'}其中key ='123';
UPDATE details SET detail = detail + {'col20000':'ABCD'}其中key ='123';但是,我想阅读一个单独的细节:
$ b $ b select detail [col1] where key ='123'
$ b b
当执行此查询时,我收到以下错误:
在输入'['
这将有效吗,还是需要不同的方法?
如果您想以更细的级别访问元组,并且仍然能够询问给定键的所有数据对是什么,则应该使用这样的表:
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 =?
。
I am trying to create a WIDE Column Table, 20,000+ columns
Initially I was thinking I would use:
CREATE TABLE details (
key TEXT,
detail map<TEXT, TEXT>
PRIMARY KEY (KEY)
);
Inserting into this table works fine
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)
);
This will allow SELECT * FROM details WHERE key = ?
as well as SELECT * FROM detail WHERE key = ? AND detail_key = ?
.
这篇关于从映射中选择特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文