如何在 JSON 数组的中间插入新值?

How to insert new value in the middle of a JSON array?

我的 table 中有一个 JSON 类型字段,它的值是这样的

[1, 3]

我想在数组中间插入另一个值,使用类似 json 拼接函数的东西(我知道它不存在)

/* JSON_ARRAY_SPLICE(array, start, deleteCount, itemToInsert) */
JSON_ARRAY_SPLICE('[1, 3]', 1, 0, 2)
>>> [1, 2, 3]

我正在使用 php,我可以创建一个函数来执行此操作,但我正在寻找 mysql 解决方案。有什么办法可以实现吗?

mysql> set @j = '[1, 3]';

mysql> select json_array_insert(@j, '$[1]', 2) as new_j;
+-----------+
| new_j     |
+-----------+
| [1, 2, 3] |
+-----------+