MariaDBでJSONオブジェクトリストの指定した位置の最後に要素を追加する

環境
MariaDB 10.6.4
Windows10 home 64bit

書式
JSON_ARRAY_APPEND('jsonオブジェクト’,’位置’,’追加要素’)
JSON_ARRAY_APPENDを使用して、リストの指定した位置の最後に要素を追加します。

使用例1
SQL構文

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
SELECT
JSON_ARRAY_APPEND('{"x": 6, "y": 7}', '$.x', 8) result
SELECT JSON_ARRAY_APPEND('{"x": 6, "y": 7}', '$.x', 8) result
SELECT 
JSON_ARRAY_APPEND('{"x": 6, "y": 7}', '$.x', 8) result

実行結果
{“x": [6, 8], “y": 7}

使用例2 
SQL構文

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
SELECT
JSON_ARRAY_APPEND('{"x": 6, "y": 7}', '$.x', 9)
SELECT JSON_ARRAY_APPEND('{"x": 6, "y": 7}', '$.x', 9)
SELECT 
JSON_ARRAY_APPEND('{"x": 6, "y": 7}', '$.x', 9)

実行結果
{“x": 1001, “y": [2002, 3003]

MariaDB

Posted by arkgame