我在text[]
中{1,32}
返回plv8
,我必须比较下面json的内容:
'{"title":"Televisão em cores"
, "answers":[{"weight":0, "weight2":1, "title":"Não tem"}
, {"weight":1, "weight2":2, "title":"1"}
, {"weight":2, "weight2":4, "title":"2"}
, {"weight":3, "weight2":8, "title":"3"}
, {"weight":4, "weight2":16, "title":"4 ou +"}]}'
如何获取所有名称weight2
并将其转换为text[]
?喜欢{1,2,4,8,16}
?
答案 0 :(得分:1)
对于Postgres 9.3中的单个json
值j
:
SELECT ARRAY(SELECT json_array_elements(j->'answers')->>'weight2');
结果:
array
{1,2,4,8,16}