Postgresql 如何显示存储在jsonb中的数组
我将信息存储在postgres9.5数据库jsonb列的数组中: { "status" : "NOK", "info" : [{ "type" : "TYPE1", "error" : [], "values" : [-44.995882968879044, -32.84752217736367, -18.645252496214137, -5.917307355383778], "sources" : [{ "id" : "54374c62", "type" : "regular", "distance" : { "to" : 0.9378531073446326, "from" : 0.0 } } ], "algorithm" : "rel", } ] } 您可以使用jsonb_数组_元素Postgresql 如何显示存储在jsonb中的数组,postgresql,Postgresql,我将信息存储在postgres9.5数据库jsonb列的数组中: { "status" : "NOK", "info" : [{ "type" : "TYPE1", "error" : [], "values" : [-44.995882968879044, -32.84752217736367, -18.645252496214137, -5.917307355383778],
请注意,如果info数组中有多个元素,则会得到相同行的重复结果。请添加预期结果。我预期:| ID |-44.99,.| TYPE1 | rel |问题是我无法显示数组中存储的信息。
SELECT id,
column_jsonb -> 'status' as status,
column_jsonb -> 'info' -> 'value' as value,
column_jsonb -> 'info' -> 'type' as type,
column_jsonb -> 'info' -> 'algorithm' as algorithm
FROM data.transaction
where id = '8db348e1-a8ec'
with the_table(id, column_jsonb ) as(
select '8db348e1-a8ec'::text, '{"status" : "NOK",
"info" : [{
"type" : "TYPE1",
"error" : [],
"values" : [-44.995882968879044, -32.84752217736367, -18.645252496214137, -5.917307355383778],
"sources" : [{
"id" : "54374c62",
"type" : "regular",
"distance" : {
"to" : 0.9378531073446326,
"from" : 0.0
}
}
],
"algorithm" : "rel"
}
]
}'::jsonb
)
select
the_table.id,
the_table.column_jsonb->'status',
j.value->'type',
j.value->'values',
j.value->'algorithm'
from the_table
join lateral jsonb_array_elements(column_jsonb -> 'info') as j
on true
where
the_table.id = '8db348e1-a8ec'