[MDEV-30304] Json Range only affects first row of the result set Created: 2022-12-26  Updated: 2023-01-25  Resolved: 2023-01-18

Status: Closed
Project: MariaDB Server
Component/s: JSON
Affects Version/s: 10.9.4, 10.10.2, 10.9, 10.10, 10.11
Fix Version/s: 10.9.5, 10.10.3

Type: Bug Priority: Critical
Reporter: Richard Stracke Assignee: Rucha Deodhar
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Duplicate
is duplicated by MDEV-30308 Query using JSON_EXTRACT on a json ob... Closed
is duplicated by MDEV-30466 Extracting value from a JSON array us... Closed
Relates
relates to MDEV-27911 Implement range notation for json path Closed

 Description   

To reproduce:

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

Expected result:

[{"id": 1, "name": "Monty"}, {"id": 2, "name": "Widenius"}]
[{"id": 1, "name": "Monty"}, {"id": 2, "name": "Widenius"}]

Current result

[{"id": 1, "name": "Monty"}, {"id": 2, "name": "Widenius"}]
{"id": 1, "name": "Monty"}



 Comments   
Comment by Alice Sherepa [ 2022-12-28 ]

Also when using * instead of json range (MDEV-30308):

MariaDB [test]> SELECT JSON_EXTRACT(j, '$[*]')  FROM t3 ;
+-------------------------------------------------------------+
| JSON_EXTRACT(j, '$[*]')                                     |
+-------------------------------------------------------------+
| [{"id": 1, "name": "Monty"}, {"id": 2, "name": "Widenius"}] |
| {"id": 1, "name": "Monty"}                                  |
+-------------------------------------------------------------+
2 rows in set (0,001 sec)

Comment by Rucha Deodhar [ 2022-12-29 ]

Patch: https://github.com/MariaDB/server/commit/57c685950c019f6c8c73eea9e1edae3db732d6af

Comment by Alexey Botchkov [ 2023-01-17 ]

ok to push.

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