/ / extraer claves / valores json específicos de la tabla jsonb de postgresql - json, postgresql

extraer claves / valores json específicos de la tabla postgresql jsonb - json, postgresql

Estoy usando postgres 9.5 y tengo una tabla como esta:

create table t1 (
id serial,
fkid int not null,
tstamp timestamp with time zone,
data jsonb
)

un json típico es:

{
"WifiStatistic": {
"Interfaces": {
"wlan0": {
"qualityLevel": {
"type": "graph",
"unit": "string",
"value": "75",
"graphDisplayName": "Quality level"
},
"SNR": {
"type": "graph",
"unit": "string",
"value": "75",
"graphDisplayName": "SNR"}
}
}
}
}

El "id" como resultado de una consulta que extrae el nivel de calidad es un conjunto de registros como:

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

¿Qué tipo de consulta puedo usar?

Respuestas

0 para la respuesta № 1

Gracias a @VaoTsun por su comentario, terminé usando esto:

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

Estaba intentando recuperar dos valores con una sola selección de json, eso es lo que me desconcertó.