[MDEV-23004] When using GROUP BY with JSON_ARRAYAGG with joint table, the square brackets are not included Created: 2020-06-24 Updated: 2022-11-11 Resolved: 2021-06-28 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | JSON |
| Affects Version/s: | 10.5.4 |
| Fix Version/s: | 10.5.12 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Dávid Szöke | Assignee: | Alexey Botchkov |
| Resolution: | Fixed | Votes: | 2 |
| Labels: | JSON, JSON_ARRAYAGG, MariaDB | ||
| Environment: |
Ubuntu 18.04LTS Server, MariaDB 10.5.4 |
||
| Issue Links: |
|
||||||||
| Description |
|
When using without the GROUP BY, the square brackets are there, but when I add GROUP BY to the query the square brackets disappear.
Expected result:
Actual result:
|
| Comments |
| Comment by Varun Gupta (Inactive) [ 2020-06-29 ] | ||||||||||||||||||||
|
Here is a test case with values
| ||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2020-06-29 ] | ||||||||||||||||||||
|
I tried to make a fix for this but when i run the query I get this output
The json value here is printed in text form. | ||||||||||||||||||||
| Comment by Dávid Szöke [ 2020-06-29 ] | ||||||||||||||||||||
|
If I run this query, it is giving me the same result as for you, with brackets. But if I run the original query, it is giving me the result that I got, without the brackets. And also what I noticed is that if I select only the id, it works, but if I select anything else, even if it is alone in the JSON, it loses the brackets.
| ||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2020-06-29 ] | ||||||||||||||||||||
|
Hi davidszoke I think the problem is reproducible with my case too, though i tested with the MYISAM storage engine. The case where the query does not work is when we use the temporary table to store the join and then perform the grouping in accordance to the GROUP BY clause. The EXPLAIN shows
and the result is like
| ||||||||||||||||||||
| Comment by Elena Stepanova [ 2020-07-01 ] | ||||||||||||||||||||
|
Here is a test case without JOIN which loses brackets in a similar way:
Same with sql_buffer_result variable instead of the SELECT option.
| ||||||||||||||||||||
| Comment by Neil Hughes [ 2021-03-14 ] | ||||||||||||||||||||
|
Relieved to find this thread. I've been having problems for days with inconsistent results from JSON_ARRAYAGG on two servers, one running 10.5.7 and one running 10.5.8. I assumed I was doing something wrong but it appears this is a known issue since last year. As others have said above, sometimes the square brackets are missing entirely - this seems to be related to the GROUP BY clause as mentioned above.. And sometimes selecting a varchar column it includes the square brackets but misses out the quotes, so I end up with invalid JSON arrays such as [these, should, be, in, quotes]. I've put together a hack in my code to massage the output to the correct format but it feels fragile so I thought I'd ask if there is a fix in the pipeline? | ||||||||||||||||||||
| Comment by Alexey Botchkov [ 2021-06-28 ] | ||||||||||||||||||||
|
https://github.com/MariaDB/server/commit/98c7916f0f29fb20cf2b8c8fa498f6033a07a89c |