create schema test_json_array_append;
set current_schema to 'test_json_array_append';
select JSON_ARRAY_APPEND('[1, [2, 3]]', '$[1]', 4);
json_array_append
-------------------
[1, [2, 3, 4]]
(1 row)
select JSON_ARRAY_APPEND('[1, [2, 3]]', '$[0]', 4);
json_array_append
-------------------
[[1, 4], [2, 3]]
(1 row)
select JSON_ARRAY_APPEND('[1, [2, 3]]', '$[1][0]', 4);
json_array_append
-------------------
[1, [[2, 4], 3]]
(1 row)
select JSON_ARRAY_APPEND('{"name": "Tim", "hobby": ["car"]}', '$.hobby', 'food');
json_array_append
-------------------------------------------
{"name": "Tim", "hobby": ["car", "food"]}
(1 row)
select JSON_ARRAY_APPEND('{"name": "Tim", "hobby": ["car"]}', '$.name', 'food');
json_array_append
---------------------------------------------
{"name": ["Tim", "food"], "hobby": ["car"]}
(1 row)
select JSON_ARRAY_APPEND('{"name": "Tim", "hobby": ["car"]}', '$.hobby[0]', 'food');
json_array_append
---------------------------------------------
{"name": "Tim", "hobby": [["car", "food"]]}
(1 row)
select JSON_ARRAY_APPEND('[1, 2]', '$[1]', 3);
json_array_append
-------------------
[1, [2, 3]]
(1 row)
select JSON_ARRAY_APPEND('[1, 2]', '$[0]', 3);
json_array_append
-------------------
[[1, 3], 2]
(1 row)
select JSON_ARRAY_APPEND('[1, 2]', '$[1]', 4);
json_array_append
-------------------
[1, [2, 4]]
(1 row)
select JSON_ARRAY_APPEND('{"name": "Tim", "hobby": "car"}', '$.hobby', 'food');
json_array_append
-------------------------------------------
{"name": "Tim", "hobby": ["car", "food"]}
(1 row)
select JSON_ARRAY_APPEND('{"name": "Tim", "hobby": "car"}', '$.name', 'food');
json_array_append
-------------------------------------------
{"name": ["Tim", "food"], "hobby": "car"}
(1 row)
select JSON_ARRAY_APPEND('{"name": "Tim", "hobby": "car"}', '$.hobby', 'drink');
json_array_append
--------------------------------------------
{"name": "Tim", "hobby": ["car", "drink"]}
(1 row)
select JSON_ARRAY_APPEND(null, '$[1]', 4);
json_array_append
-------------------
(1 row)
select JSON_ARRAY_APPEND('[1, [2, 3]]', null, 4);
json_array_append
-------------------
(1 row)
select JSON_ARRAY_APPEND('[1, [2, 3]]', '$', 4);
json_array_append
-------------------
[1, [2, 3], 4]
(1 row)
select JSON_ARRAY_APPEND('[1, [2, 3]]', '$[3]', 4);
json_array_append
-------------------
[1, [2, 3]]
(1 row)
select JSON_ARRAY_APPEND(null, '$.hobby', 'food');
json_array_append
-------------------
(1 row)
select JSON_ARRAY_APPEND('{"name": "Tim", "hobby": ["car"]}', null, 'food');
json_array_append
-------------------
(1 row)
select JSON_ARRAY_APPEND('{"name": "Tim", "hobby": ["car"]}', '$.car', 'food');
json_array_append
-----------------------------------
{"name": "Tim", "hobby": ["car"]}
(1 row)
select JSON_ARRAY_APPEND('{"name": "Tim", "hobby": ["car"]}', '$', 'food');
json_array_append
---------------------------------------------
[{"name": "Tim", "hobby": ["car"]}, "food"]
(1 row)
select JSON_ARRAY_APPEND('[1, [2, 3]]', '$[1]', 4, '$[1]', 5);
json_array_append
-------------------
[1, [2, 3, 4, 5]]
(1 row)
select JSON_ARRAY_APPEND('[1, [2, 3]]', '$[1]', null);
json_array_append
-------------------
[1, [2, 3, null]]
(1 row)
select JSON_ARRAY_APPEND('[1, [2, 3]]', '$[1]', true);
json_array_append
-------------------
[1, [2, 3, true]]
(1 row)
select JSON_ARRAY_APPEND('[1, [2, 3]]', '$[1]', '');
json_array_append
-------------------
[1, [2, 3, ""]]
(1 row)
select JSON_ARRAY_APPEND('[1, [2, 3]]', '$[1]', json '{"x": 3, "y": [1,2,3]}');
json_array_append
---------------------------------------
[1, [2, 3, {"x": 3, "y": [1, 2, 3]}]]
(1 row)
select JSON_ARRAY_APPEND('[1, [2, 3]]', '$[1]', 1.2);
json_array_append
-------------------
[1, [2, 3, 1.2]]
(1 row)
select JSON_ARRAY_APPEND('[1, [2, 3]]', '[1]', 4);
ERROR: Invalid JSON path expression. The error is around argument 1.
CONTEXT: referenced column: json_array_append
select JSON_ARRAY_APPEND('[1, [2, 3]]', '$[]', 4);
ERROR: Invalid JSON path expression. The error is around argument 1.
CONTEXT: referenced column: json_array_append
select JSON_ARRAY_APPEND('[1, [2, 3]]', '$[1', 4);
ERROR: Invalid JSON path expression. The error is around argument 1.
CONTEXT: referenced column: json_array_append
select JSON_ARRAY_APPEND('[1, [2, 3]]', '$.1', 4);
ERROR: Invalid JSON path expression. The error is around argument 1.
CONTEXT: referenced column: json_array_append
select JSON_ARRAY_APPEND('[1, [2, 3]]', '$..1', 4);
ERROR: Invalid JSON path expression. The error is around argument 1.
CONTEXT: referenced column: json_array_append
select JSON_ARRAY_APPEND('[1, [2, 3]]', '$[*]', 4);
ERROR: In this situation, path expressions may not contain the * and ** tokens.
CONTEXT: referenced column: json_array_append
select JSON_ARRAY_APPEND('[1, [2, 3]]', '$[*]', 日);
ERROR: column "日" does not exist
LINE 1: select JSON_ARRAY_APPEND('[1, [2, 3]]', '$[*]', 日);
^
CONTEXT: referenced column: json_array_append
select JSON_ARRAY_APPEND('[1, [2, 3]]', ' ', 4);
ERROR: Invalid JSON path expression. The error is around argument 1.
CONTEXT: referenced column: json_array_append
select JSON_ARRAY_APPEND('[1, [2, 3]]'::varchar(20), '$[1]', null);
json_array_append
-------------------
[1, [2, 3, null]]
(1 row)
select JSON_ARRAY_APPEND('[1, [2, 3]]'::bpchar, '$[1]', null);
json_array_append
-------------------
[1, [2, 3, null]]
(1 row)
select JSON_ARRAY_APPEND('[1, [2, 3]]', '$[0]', null);
json_array_append
---------------------
[[1, null], [2, 3]]
(1 row)
select json_array_append('[1]', '$[0]', 341522654875451.12345678901234567890123456789012345678901234567890);
json_array_append
---------------------------------------------------------------------------
[[1, 341522654875451.12345678901234567890123456789012345678901234567890]]
(1 row)
drop schema test_json_array_append cascade;
reset current_schema;