【问题标题】:Query to concatenate two json arrays in MySQL?查询以连接 MySQL 中的两个 json 数组?
【发布时间】:2021-12-30 06:19:17
【问题描述】:

我有一个 json 数据类型的列,其值类似于“[1,2,3,4]”,并且想要将“[5,6]”之类的值添加到这个 json 数组中。检查并遇到 连接运算符,即 || 。我正在尝试类似
update user_roles set roles = (roles|| '[111]') where id=?1; 的东西。
期望的结果:-'[1,2,3,4,5,6]'
给出下面提到的错误:
错误代码:3156。CAST 到 DOUBLE 列角色的 JSON 值无效

【问题讨论】:

    标签: mysql sql json


    【解决方案1】:

    来自12.18.4 Functions That Modify JSON Values的列表

    您可以使用:select json_merge_preserve('[1,2,3,4]','[5,6]');

    这将输出:[1, 2, 3, 4, 5, 6]

    【讨论】:

      猜你喜欢
      • 2014-11-07
      • 2011-05-16
      • 2017-03-17
      • 2021-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多