[MDEV-32888] Inconsistent results involving JSON operations Created: 2023-11-26 Updated: 2023-11-27 Resolved: 2023-11-27 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | JSON |
| Affects Version/s: | 10.6.16, 10.4.33 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Major |
| Reporter: | Andreas Hinderberger | Assignee: | Alexander Barkov |
| Resolution: | Not a Bug | Votes: | 1 |
| Labels: | None | ||
| Environment: |
Windows 11 |
||
| Description |
|
When executing the following statments on MariaDB 10.6.14
I receive the following results: For @json_result_1:
And for @json_result_2:
How does it come that I retrieve different result? Aren't those JSON string supposed to be internally all treated as TEXT? |
| Comments |
| Comment by Andreas Hinderberger [ 2023-11-26 ] | |||
|
Forgot...
This produces the same expected result as for @json_result_2 | |||
| Comment by Sergei Golubchik [ 2023-11-27 ] | |||
|
It behaves as expected. MariaDB knows that the output of JSON_OBJECT() is a json. But when you store it in a variable, it loses its "json-ness" and becomes a literal string. To force a string to be interpreted as a json, you can use, indeed, JSON_EXTRACT, or, just JSON_COMPACT(). | |||
| Comment by Andreas Hinderberger [ 2023-11-27 ] | |||
|
In my opinion it should keep the "json-ness" or whenever JSON_OBJECT uses that "literal string" it should check whether it's a valid json and treat it like that? | |||
| Comment by Sergei Golubchik [ 2023-11-27 ] | |||
|
Yes, but the value will lose its "json-ness" anyway when being stored in a table. Or in a stored routine variable. The reason for this — SQL Standard 2016, which very explicitly said
which is why MariaDB doesn't have a JSON data type. In the newer SQL Standard, as far as I know, they've changed their minds, and wrote that there is a distinct data type for JSON. We'll need to implement that to be standard compatible again and then the behavior will be much more intuitive. |