PostgreSQL 解析json字段
一、解析json数组
select json_array_elements(lv_num_json)->'l1' lv,json_array_elements(lv_num_json)->'num' num from (
select '[{"l1": 8, "num": 1}, {"l1": 9, "num": 10}]'::json lv_num_json
)as t1
查询结果
二、解析json对象
SELECT json_object_field('{"l1": 8, "num": 1}', 'l1') as l1, json_object_field('{"l1": 8, "num": 1}', 'num') as num
-- 字段
SELECT json_object_field_text(result::json, 'id') as op_id FROM test
查询结果