Mysql 5.7 开始支持 JSON,应用场景有 记录数据操作日志, 保留的扩展字段 等等。

  1. 插入 json 数据
insert into test (json_field) value("{\"col\": val1, \"col2\":\"val2\"...}");
insert into test (json_field) value(json_object(col1,val2, col2, val2)));
  1. 修改数据
update test set json_field = json_set(json_field, '$.col", val);

  1. 查询数据
select json_extract(json_field, "$.col") from test;

select JSON_UNQUOTE(json_extract(json_field, "$.col")) from test;

select json_field -> "$.col"from test;

select json_field ->> "$.col" from test;

参照资料

  1. MySQL 5.7 新增加的 JSON 特性对应的 json 方法
  2. The JSON Data Type

相关文章:

  • 2022-12-23
  • 2021-04-02
  • 2021-11-01
  • 2022-12-23
  • 2021-07-04
  • 2022-01-13
  • 2022-12-23
  • 2021-05-06
猜你喜欢
  • 2021-12-20
  • 2022-02-05
  • 2021-10-22
  • 2022-03-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案