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


查询结果

posted @ 2021-08-18 18:01  hziwei  阅读(2542)  评论(0编辑  收藏  举报