Comments - JSON_INSERT
Content reproduced on this site is the property of its respective owners,
and this content is not reviewed in advance by MariaDB. The views, information and opinions
expressed by this content do not necessarily represent those of MariaDB or any other party.
can i insert wiith a josn,not a string? just like this
it use as a string
mysql> SET @j = '{ "a": 1, "b": [2, 3]}'; mysql> SELECT JSON_INSERT(@j, '$.a', 10, '$.c', '[true, false]'); +----------------------------------------------------+ | JSON_INSERT(@j, '$.a', 10, '$.c', '[true, false]') | +----------------------------------------------------+ | {"a": 1, "b": [2, 3], "c": "[true, false]"} | +----------------------------------------------------+it use as a json
mysql> SELECT JSON_INSERT(@j, '$.a', 10, '$.c', CAST('[true, false]' AS JSON)); +------------------------------------------------------------------+ | JSON_INSERT(@j, '$.a', 10, '$.c', CAST('[true, false]' AS JSON)) | +------------------------------------------------------------------+ | {"a": 1, "b": [2, 3], "c": [true, false]} | +------------------------------------------------------------------+ 1 row in set (0.00 sec)You can use JSON_EXTRACT for it:
MariaDB [test]> SET @j = '{ "a": 1, "b": [2, 3]}'; Query OK, 0 rows affected (0.000 sec) MariaDB [test]> SELECT JSON_INSERT(@j, '$.a', 10, '$.c', JSON_EXTRACT('[true, false]', '$')); +-----------------------------------------------------------------------+ | JSON_INSERT(@j, '$.a', 10, '$.c', JSON_EXTRACT('[true, false]', '$')) | +-----------------------------------------------------------------------+ | {"a": 1, "b": [2, 3], "c": [true, false]} | +-----------------------------------------------------------------------+ 1 row in set (0.000 sec)