查询JSONArray类型中的值

如下,f1_json_text字段为text类型的字段,但是其存储的值是JSONArray的,可以通过Postgre的json_array_elements方法进行JSON的解析查询

select t1.id, t1.title, t1.nodetreeid from (

SELECT id, title, f1_json_text, elements->>'id' as myid

FROM table1, json_array_elements(f1_json_text::json) AS elements

) t1 where t1.myid='666';

备注:

1.json_array_elements是Postgre自带的解析JSONArray类型的方法

2.elements->>'id' as myid 将数组的中的每个元素(键值对)的值解析了出来,‘id’就是键值对的key, 这样解析出的myid就是id键值对对应的值.

Comment IconComment Icon
Icon
评论 0
时间↑ 点赞↓

Comment Icon