[MDEV-30678] Json Range not work wirh JSON_REMOVE Created: 2023-02-17  Updated: 2023-03-29  Resolved: 2023-03-29

Status: Closed
Project: MariaDB Server
Component/s: JSON
Affects Version/s: 10.11.2
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Richard Stracke Assignee: Ian Gilfillan
Resolution: Fixed Votes: 0
Labels: JSON_REMOVE, documentation


 Description   

to reproduce:

DROP TABLE t3;
 
CREATE TABLE t3 (
 
  j JSON 
 
);
 
 
 
INSERT INTO t3 (j) VALUES ('[{"id": 1, "name": "Monty"},{"id": 2, "name": "Widenius"},{"id": 3, "name": "Michael"}]');
 
INSERT INTO t3 (j) VALUES ('[{"id": 1, "name": "Monty"},{"id": 2, "name": "Widenius"},{"id": 3, "name": "Michael"}]');
 
 
 
SELECT JSON_REMOVE(j, '$[0 to 1]')  FROM t

Result
(NULL)
(NULL)



 Comments   
Comment by Alice Sherepa [ 2023-02-20 ]

The warning says that range is not allowed.

MariaDB [test]> SELECT JSON_REMOVE(j, '$[0 to 1]')  FROM t3;
+-----------------------------+
| JSON_REMOVE(j, '$[0 to 1]') |
+-----------------------------+
| NULL                        |
| NULL                        |
+-----------------------------+
2 rows in set, 2 warnings (0,001 sec)
 
Warning (Code 4044): Wildcards or range in JSON path not allowed in argument 2 to function 'json_remove'
Warning (Code 4044): Wildcards or range in JSON path not allowed in argument 2 to function 'json_remove'

It should be added to KB (https://mariadb.com/kb/en/json_remove/)
Also docs says "An error will occur if JSON document is invalid, the path is invalid or if the path contains a * or ** wildcard.", while NULL is retuned + warning:

MariaDB [test]> SELECT JSON_REMOVE('["A", "B", ["C", "D"], "E"]', '$[]');
+---------------------------------------------------+
| JSON_REMOVE('["A", "B", ["C", "D"], "E"]', '$[]') |
+---------------------------------------------------+
| NULL                                              |
+---------------------------------------------------+
1 row in set, 1 warning (0,000 sec)
 
Warning (Code 4042): Syntax error in JSON path in argument 2 to function 'json_remove' at position 3

Comment by Weijun Huang [ 2023-03-06 ]

Perhaps it should be considered as an intentional enforcement feature rather than a bug?

Comment by Ian Gilfillan [ 2023-03-29 ]

Documented on https://mariadb.com/kb/en/json_remove, as this appears to be by design.

Generated at Thu Feb 08 10:18:05 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.