[MDEV-17121] JSON_ARRAY_APPEND Created: 2018-09-03  Updated: 2018-09-11  Resolved: 2018-09-11

Status: Closed
Project: MariaDB Server
Component/s: JSON
Affects Version/s: 10.3.9, 10.2, 10.3
Fix Version/s: 10.2.18

Type: Bug Priority: Major
Reporter: Aleksey M. Assignee: Alexey Botchkov
Resolution: Fixed Votes: 0
Labels: None
Environment:

Ubuntu 18.04


Issue Links:
Relates
relates to MDEV-17001 JSON_MERGE returns nullwhen merging e... Closed

 Description   

CREATE TEMPORARY TABLE a (
  `data` mediumtext DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
INSERT INTO a VALUES ('{}');
 
UPDATE a SET 
  data = JSON_INSERT(data, '$.messages', JSON_QUERY('[]', '$')) ,
  data = JSON_ARRAY_APPEND(data, '$.messages', JSON_QUERY('{"date":"2018-09-03","text":"mmmmmmm"}', '$'));
 
-- Error (4038): Syntax error in JSON text in argument 1 to function 'json_array_append' at position 15
 
-- BUT, If in "JSON_QUERY('[]', '$'))" array is not empty:
 
UPDATE a SET 
  data = JSON_INSERT(data, '$.messages', JSON_QUERY('["AAAAA"]', '$')) ,
  data = JSON_ARRAY_APPEND(data, '$.messages', JSON_QUERY('{"date":"2018-09-03","text":"mmmmmmm"}', '$'));
 
-- Not errors



 Comments   
Comment by Alice Sherepa [ 2018-09-03 ]

Thanks for the report!
reproduced as described on MariaDB 10.2, 10.3

MariaDB [test]> select JSON_ARRAY_APPEND('{"a": []}', '$.a', JSON_QUERY('{"date":"2018-09-03","text":"mmmmmmm"}', '$')) ;
+--------------------------------------------------------------------------------------------------+
| JSON_ARRAY_APPEND('{"a": []}', '$.a', JSON_QUERY('{"date":"2018-09-03","text":"mmmmmmm"}', '$')) |
+--------------------------------------------------------------------------------------------------+
| NULL                                                                                             |
+--------------------------------------------------------------------------------------------------+
1 row in set, 1 warning (0.000 sec)
 
Warning (Code 4038): Syntax error in JSON text in argument 1 to function 'json_array_append' at position 8
MariaDB [test]> select JSON_ARRAY_APPEND('{"a": [{}]}', '$.a', JSON_QUERY('{"date":"2018-09-03","text":"mmmmmmm"}', '$')) ;
+----------------------------------------------------------------------------------------------------+
| JSON_ARRAY_APPEND('{"a": [{}]}', '$.a', JSON_QUERY('{"date":"2018-09-03","text":"mmmmmmm"}', '$')) |
+----------------------------------------------------------------------------------------------------+
| {"a": [{}, {"date": "2018-09-03", "text": "mmmmmmm"}]}                                             |
+----------------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)

Comment by Alexey Botchkov [ 2018-09-11 ]

http://lists.askmonty.org/pipermail/commits/2018-September/012907.html

Generated at Thu Feb 08 08:34:04 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.