- 准备数据
建表
create table ay_json_test(
id varchar primary key,
name varchar,
json_value json
)
插入数据:
insert into ay_json_test values('001','ay','{
"ay_name":"阿毅",
"home":{
"type":{"interval":
"5m"
},
"love":"now",
"you":"None"
},
"values":{
"event":["cpu_r","cpu_w"],
"data":["cpu_r"],
"threshold":[1,1]
},
"objects":{
"al":"beauty"
}
}');
查询
select id,name,json_value->>'ay_name' as ayName from ay_json_test where json_value ->>'ay_name' = '阿毅'
select id,name,json_value->>'ay_name' as ayName,json_value ->> 'objects' as objects from ay_json_test
where json_value ->>'ay_name' = '阿毅'
select json_value -> 'values'#>>'{data,0}' as objects from ay_json_test
where json_value ->>'ay_name' = '阿毅'
更新数据
update ay_json_test set json_value = '{
"ay_name":"阿毅_change",
"home":{
"type":{"interval_change":
"5m"
},
"love":"now_change",
"you":"None_change"
},
"values":{
"event":["cpu_r_change","cpu_w_change"],
"data":["cpu_r_change"],
"array":[999,5]
},
"objects":{
"al":"beauty"
}
}'
where json_value ->> 'ay_name' = '阿毅'
删除
delete from ay_json_test where json_value ->> 'ay_name' = '阿毅_change'
原文连接:https://blog.csdn.net/huangwenyi1010/article/details/51224886