@@ -306,7 +306,7 @@ select json_merge('string', 123);
306306json_merge('string', 123)
307307NULL
308308Warnings:
309- Warning 4038 Syntax error in JSON text in argument 1 to function 'json_merge ' at position 1
309+ Warning 4038 Syntax error in JSON text in argument 1 to function 'json_merge_preserve ' at position 1
310310select json_merge('"string"', 123);
311311json_merge('"string"', 123)
312312["string", 123]
@@ -326,7 +326,7 @@ select json_merge('a','b');
326326json_merge('a','b')
327327NULL
328328Warnings:
329- Warning 4038 Syntax error in JSON text in argument 1 to function 'json_merge ' at position 1
329+ Warning 4038 Syntax error in JSON text in argument 1 to function 'json_merge_preserve ' at position 1
330330select json_merge('{"a":"b"}','{"c":"d"}');
331331json_merge('{"a":"b"}','{"c":"d"}')
332332{"a": "b", "c": "d"}
@@ -843,6 +843,77 @@ SELECT CHARSET(JSON_OBJECT());
843843CHARSET(JSON_OBJECT())
844844latin1
845845#
846+ # MDEV-13992 Implement JSON_MERGE_PATCH
847+ #
848+ CREATE TABLE merge_t(
849+ id INT PRIMARY KEY AUTO_INCREMENT,
850+ target VARCHAR(100), patch VARCHAR(100)
851+ );
852+ INSERT INTO merge_t(target, patch) VALUES
853+ ('{"a":"b"}', '{"a":"c"}'),
854+ ('{"a":"b"}', '{"b":"c"}'),
855+ ('{"a":"b"}', '{"a":null}'),
856+ ('{"a":"b", "b":"c"}', '{"a":null}'),
857+ ('{"a":["b"]}', '{"a":"c"}'),
858+ ('{"a":"c"}', '{"a":["b"]}'),
859+ ('{"a": {"b":"c"}}', '{"a": {"b":"d", "c":null}}'),
860+ ('{"a":[{"b":"c"}]}', '{"a": [1]}'),
861+ ('["a","b"]', '["c","d"]'),
862+ ('{"a":"b"}', '["c"]'),
863+ ('{"a":"foo"}', 'null'),
864+ ('{"a":"foo"}', '"bar"'),
865+ ('{"e":null}', '{"a":1}'),
866+ ('[1,2]', '{"a":"b", "c":null}'),
867+ ('{}', '{"a":{"bb":{"ccc":null}}}'),
868+ (NULL, '{}'),
869+ ('{}', NULL);
870+ SELECT id, target, patch,
871+ JSON_MERGE_PATCH(target, patch) AS merged,
872+ JSON_EXTRACT(JSON_MERGE_PATCH(target, patch), '$.a') AS a
873+ FROM merge_t ORDER BY id;
874+ id target patch merged a
875+ 1 {"a":"b"} {"a":"c"} {"a": "c"} "c"
876+ 2 {"a":"b"} {"b":"c"} {"a": "b", "b": "c"} "b"
877+ 3 {"a":"b"} {"a":null} {} NULL
878+ 4 {"a":"b", "b":"c"} {"a":null} {"b": "c"} NULL
879+ 5 {"a":["b"]} {"a":"c"} {"a": "c"} "c"
880+ 6 {"a":"c"} {"a":["b"]} {"a": ["b"]} ["b"]
881+ 7 {"a": {"b":"c"}} {"a": {"b":"d", "c":null}} {"a": {"b": "d"}} {"b": "d"}
882+ 8 {"a":[{"b":"c"}]} {"a": [1]} {"a": [1]} [1]
883+ 9 ["a","b"] ["c","d"] ["c", "d"] NULL
884+ 10 {"a":"b"} ["c"] ["c"] NULL
885+ 11 {"a":"foo"} null null NULL
886+ 12 {"a":"foo"} "bar" "bar" NULL
887+ 13 {"e":null} {"a":1} {"e": null, "a": 1} 1
888+ 14 [1,2] {"a":"b", "c":null} {"a": "b"} "b"
889+ 15 {} {"a":{"bb":{"ccc":null}}} {"a": {"bb": {}}} {"bb": {}}
890+ 16 NULL {} NULL NULL
891+ 17 {} NULL NULL NULL
892+ DROP TABLE merge_t;
893+ SELECT JSON_MERGE_PATCH('{"a":"b"}', NULL, '{"c":"d"}');
894+ JSON_MERGE_PATCH('{"a":"b"}', NULL, '{"c":"d"}')
895+ NULL
896+ SELECT JSON_MERGE_PATCH(NULL, '[1,2,3]');
897+ JSON_MERGE_PATCH(NULL, '[1,2,3]')
898+ [1, 2, 3]
899+ SELECT JSON_MERGE_PATCH('{"a":"b"}', NULL, '[1,2,3]', '{"c":null,"d":"e"}');
900+ JSON_MERGE_PATCH('{"a":"b"}', NULL, '[1,2,3]', '{"c":null,"d":"e"}')
901+ {"d": "e"}
902+ SELECT JSON_MERGE_PATCH();
903+ ERROR 42000: Incorrect parameter count in the call to native function 'JSON_MERGE_PATCH'
904+ SELECT JSON_MERGE_PATCH('{}');
905+ ERROR 42000: Incorrect parameter count in the call to native function 'JSON_MERGE_PATCH'
906+ SELECT JSON_MERGE_PATCH('{', '[1,2,3]');
907+ JSON_MERGE_PATCH('{', '[1,2,3]')
908+ NULL
909+ Warnings:
910+ Warning 4037 Unexpected end of JSON text in argument 1 to function 'json_merge_patch'
911+ SELECT JSON_MERGE_PATCH('{"a":"b"}', '[1,');
912+ JSON_MERGE_PATCH('{"a":"b"}', '[1,')
913+ NULL
914+ Warnings:
915+ Warning 4037 Unexpected end of JSON text in argument 2 to function 'json_merge_patch'
916+ #
846917# End of 10.2 tests
847918#
848919#
0 commit comments