How do I insert new values into a mysql json array?

问题: I am testing this example. JSON_TABLE – The Best of Both Worlds I understand that t1 is the table and people the array but where do I put the name of the column? INS...

问题:

I am testing this example.

JSON_TABLE – The Best of Both Worlds

I understand that t1 is the table and people the array but where do I put the name of the column?

INSERT INTO t1 VALUES (
        '{ "people": [
            { "name":"John Smith",  "address":"780 Mission St, San Francisco, CA 94103"}, 
            { "name":"Sally Brown",  "address":"75 37th Ave S, St Cloud, MN 94103"}, 
            { "name":"John Johnson",  "address":"1262 Roosevelt Trail, Raymond, ME 04071"}
         ] }'
    );

They call the column json_col but they only use it in a select query like this.

SELECT people.* 
FROM t1, 
     JSON_TABLE(json_col, '$.people[*]' COLUMNS (
                name VARCHAR(40)  PATH '$.name',
                address VARCHAR(100) PATH '$.address')
     ) people;

回答1:

json_col is the name of the column ( CREATE TABLE t1(json_col JSON); ).

For insertion, you can also use INSERT INTO t1(json_col) VALUES (...)

  • 发表于 2019-01-28 22:10
  • 阅读 ( 20 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除