Details
-
Bug
-
Status: Open (View Workflow)
-
Major
-
Resolution: Unresolved
-
11.3.2
-
None
Description
(Filing this not because I expect we will fix this [soon], but rather to document this)
MariaDB supports "lax mode" for JSON Path evaluation (there is also "strict mode" which is not supported).
The SQL Standard specifies that in this mode the JSON Path evaluator does "boxing" and "unboxing":
"boxing" means treat a JSON value "foo" as if it was in a one-element array: ["foo"].
"unboxing" means the reverse: treat ["foo"\, ... ] as if it was just "foo".
MySQL doesn't do "boxing" or "unboxing".
(EDIT: "boxing" is done, see the comments. "unboxing" is not done)
MariaDB follows MySQL and also doesn't do that.
Example:
SELECT JSON_VALUE('{"user": [{"name": "Alice"}]}', '$.user.name') AS extracted_name |
FROM DUAL; |
This returns NULL in both MariaDB and MySQL. And also in MS SQL Server (sqlfiiddle).
In OracleDB, it returns "Alice" (sqlfiddle)
In PostgreSQL,
SELECT jsonb_path_query('{"user": [{"name": "Alice"}]}', '$.user.name'); |
also returns "Alice".
This was also discussed, especially w.r.t. mongodb, in https://jira.mariadb.org/browse/MDEV-37288?focusedCommentId=310846&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-310846
More specifically, the unboxing could happen anywhere along the path, as https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/create-multikey-index-embedded/#std-label-index-create-multikey-embedded shows. This means for
set @j = '{ |
"item": "t-shirt",
|
"stock": [
|
{
|
"size": "small",
|
"quantity": 8
|
},
|
{
|
"size": "large",
|
"quantity": 10
|
}
|
]
|
}'; |
one could get something like json_extract(@j, '$.stock.quantity') = 8 to evaluate to true.
Attachments
Issue Links
- relates to
-
MDEV-40168 Indexes over JSON data based on Fulltext index
-
- In Progress
-