mysql5.7 json的一些用法

配置表添加主键
json里面每个表多加一层以主键作为key值

insert:
order_no存在
追加
-----json数组
update tracking_order
set order_info=json_array_append(order_info, ‘$.data’, cast(’{“size”: “5”, “type”: “m”, “so_no”: “345”}’ as json))
where id=111

-----json
update tracking_order
set order_info=json_merge(order_info,cast(’{“data”: {“5”:{“size”: “5”, “type”: “m”, “so_no”: “345”}}}’ as json))
where id=111

order_no不存在:
直接插入
insert into tracking_order()
values()

update
update tracking_order
set order_info=json_replace(order_info,’$.data’,cast(’{“5”:{“size”: “5”, “type”: “m”, “so_no”: “345”}}’ as json))
where id=111

delete
存在数组
update tracking_order
set order_info=json_remove(order_info,concat(’ . d a t a , s u b s t r ( s u b s t r i n g i n d e x ( j s o n u n q u o t e ( j s o n s e a r c h ( j s o n e x t r a c t ( o r d e r i n f o , .data',substr(substring_index(json_unquote(json_search(json_extract( order_info,' .data’),‘one’,1)),’.’,1),2,20)))
where id=111

不存在数组
json_remove(order_info,’$.data’)

1、对于主表的维度信息变更时,json里面的维度信息无法变更
2、对于维度信息先流过来时,无法匹配到对应的主表信息,当后续json需要用到维度信息时,无法关联

猜你喜欢

转载自blog.csdn.net/qq_22994783/article/details/84782690