[MDEV-19664] JSON_VALUE and null values Created: 2019-05-31 Updated: 2022-12-09 Resolved: 2022-12-09 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | JSON |
| Affects Version/s: | 10.4.5, 10.2, 10.3, 10.4, 10.5, 10.6, 10.7 |
| Fix Version/s: | 10.3.38, 10.4.28, 10.5.19, 10.6.12, 10.7.8 |
| Type: | Bug | Priority: | Major |
| Reporter: | Wolfgang Draxler | Assignee: | Rucha Deodhar |
| Resolution: | Duplicate | Votes: | 9 |
| Labels: | None | ||
| Environment: |
Windows |
||
| Issue Links: |
|
||||||||
| Description |
|
I have found the following bug:
I was expecting
|
| Comments |
| Comment by Elena Stepanova [ 2019-06-03 ] | |||||||||||||||||||||||||||||||
|
That's because JSON null is not the NULL. That's how we can see it, for example:
Same with MySQL 5.7. I'll leave it to holyfoot to comment whether it's supposed to be so or not. | |||||||||||||||||||||||||||||||
| Comment by Kacper Cioch (Inactive) [ 2019-11-28 ] | |||||||||||||||||||||||||||||||
|
Hey.
It returns string 'null' instead of value NULL.
tested on 10.4.10 I think it is a bug because of this (different jsdoc, same result)
| |||||||||||||||||||||||||||||||
| Comment by Jan Venekamp [ 2020-01-06 ] | |||||||||||||||||||||||||||||||
|
I think not many people would expect that null equals to the string 'null', so I second Kacper Cioch that this should be considered as a bug. This behavior bit me in an other way. Inspired by this article https://mariadb.com/resources/blog/json-with-mariadb-10-2/ I started using virtual columns based on JSON values. Here is an example of how this behaves rather differently than expected.
Expected
Actual
Workaround For other people stumbling upon this, here is a workaround:
| |||||||||||||||||||||||||||||||
| Comment by Kolbe Kegel [ 2020-02-18 ] | |||||||||||||||||||||||||||||||
|
Maybe what's needed is something like a JSON_CAST function that combines JSON_TYPE/JSON_EXTRACT/JSON_VALUE functionality to return a json path cast to the most appropriate MariaDB type. | |||||||||||||||||||||||||||||||
| Comment by Timucin Bahsi [ 2021-07-13 ] | |||||||||||||||||||||||||||||||
|
Let's explore this a little:
Output:
Now, first we see that it returns a string with "null" in it. Ok, maybe it doesn't recognize null in json, but it does when we use "NULL" in capitals. Then we see the weirdest thing, if the expression starts with the leters "null", it ignores the rest. This is very different than treating it as a string. Then we actually see it's not how it treats strings. If you don't use quotes around strings it's just null. This doesn't seem like intended at all. It doesn't see it as null, it doesn't see it as a string either. There's certainly a special case for this specific sequence of characters and it doesn't any sense that i can think of. Note: tested under MariaDB [10.3.17-MariaDB-1:10.3.17+maria~bionic] | |||||||||||||||||||||||||||||||
| Comment by Assen Totin (Inactive) [ 2021-12-02 ] | |||||||||||||||||||||||||||||||
|
Clearly a bug to me. JSON makes a very visible difference between "null" as a string and null as a value. See |