MySQL5.7以上版本json字段的处理

MySQL5.7以上版本json字段的处理

创建表:

CREATE TABLE `tb_testjson` (
	`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
	`content` JSON NULL DEFAULT NULL,
	PRIMARY KEY (`id`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
AUTO_INCREMENT=0
;

1.查询json字段的值

select content ,JSON_EXTRACT(content,"$.name") as name from tb_testjson;

#select content ,content->"$.name" as name from tb_testjson;

2.插入:
UPDATE tb_testjson SET content=JSON_ARRAY_APPEND(content,'$.name','test') WHERE id = 2;

{"age": "11", "name": ["ww", "test"]}
posted @ 2021-10-27 15:32  yongqi-911  阅读(78)  评论(0编辑  收藏  举报