/ / postgresql jsonbテーブルから特定のjsonキー/値を抽出する-json、postgresql

特定のjsonキー/値をpostgresql jsonbテーブルから抽出する - json、postgresql

私は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」は、次のようなレコードセットです。

id | fkid | tstamp     | value | graphdisplayName
-------------------------------------------------
1  |  1   | 2017-01-22 |   75  |  "Quality Level"

どのようなクエリを使用できますか?

回答:

回答№1は0

コメントしてくれた@VaoTsunに感謝します。

select
tstamp, id, fkid,
data->"WifiStatistics"->"Interfaces"->"wlan0"->"qualityLevel"->"value" as value,
data #>"{WifiStatistics, Interfaces, wlan0, qualityLevel}" ->"graphDisplayName" as dname
from data;

私は1つのjson選択で2つの値を回復しようとしていましたが、それが私を困惑させました。