| id | title | attr |
|---|---|---|
| 1 | 李白 | {“banji”:“1班”,“xueduan”:“初三”,“xuexiao”:“某某一中”,“jiaoshi_id”:“11,12”} |
取值:json_extract(json字段,"$.key值");
取學校:
select json_extract(attr,"$.xuexiao") xuexiao from table where id=1
結果:
| xuexiao |
|---|
| “某某二中” |
去掉雙引號
json_unquote()
取教師id去雙引號
select json_unquote(json_extract(attr,"$.jiaoshi_id")) jaoshi_id from table where id=1
結果:
| jiaoshi_id |
|---|
| 11,12 |
//此處有更簡便的方式未
jsondata->"$.attribute"
jsondata->>"$.attribute"
修改:
json_replace(json_字段,"$.key值",“value”);只替換;
json_set(字段,"$.shuxing",“value”);如果有替換,沒有就新增
