无法在Postgres中取消嵌套JSON

时间:2019-04-06 14:38:15

标签: json postgresql

create table json_example as
select '[{"a":1,"b":"foo"},{"a":"2","c":"bar"}]'::jsonb as value

select * from json_example

以下工作正常:

select * from json_array_elements('[{"a":1,"b":"foo"},{"a":"2","c":"bar"}]')

我想做同样的事情,唯一的区别是json来自表。如何使用json_example表值字段执行相同操作?

1 个答案:

答案 0 :(得分:2)

cross join json_array_elements 与表

select j.* from json_example cross join
json_array_elements(value) as j

DEMO