我正在使用postgres 9.5,我有一个这样的表:
create table t1 (
id serial,
fkid int not null,
tstamp timestamp with time zone,
data jsonb
)
典型的json是:
{
"WifiStatistic": {
"Interfaces": {
"wlan0": {
"qualityLevel": {
"type": "graph",
"unit": "string",
"value": "75",
"graphDisplayName": "Quality level"
},
"SNR": {
"type": "graph",
"unit": "string",
"value": "75",
"graphDisplayName": "SNR"}
}
}
}
}
提取质量等级的查询结果如下所示:
id | fkid | tstamp | value | graphdisplayName
-------------------------------------------------
1 | 1 | 2017-01-22 | 75 | "Quality Level"
我可以使用哪种查询?
答案 0 :(得分:0)
感谢@VaoTsun的评论,我最终使用了这个:
select
tstamp, id, fkid,
data->'WifiStatistics'->'Interfaces'->'wlan0'->'qualityLevel'->'value' as value,
data #>'{WifiStatistics, Interfaces, wlan0, qualityLevel}' ->'graphDisplayName' as dname
from data;
我试图用一个json选择恢复两个值,这就是困惑我的。