Details
-
Bug
-
Status: Open (View Workflow)
-
Minor
-
Resolution: Unresolved
-
10.11, 11.4, 11.8, 12.3, 13.0
Description
This is a documentation defect, not a code defect. The behaviour is
the MySQL-compatible one and is what the test suite pins; four help rows
describe it wrongly.
SELECT JSON_SET('{}', '$.a', NULL) AS s, |
JSON_REPLACE('{"a":1}', '$.a', NULL) AS r, |
JSON_ARRAY_APPEND('[1]', '$', NULL) AS a, |
JSON_ARRAY_INSERT('[1]', '$[0]', NULL) AS i; |
s r a i
|
{"a": null} {"a": null} [1, null] [null, 1] |
All four help rows say "or NULL if any of the arguments are NULL". A
NULL in the value position does not make the result NULL; it stores a
JSON null, which is the useful and expected behaviour.
How to repeat
Read the help text beside the behaviour:
SELECT JSON_SET('{"a":1}','$.b',NULL,'$.c',2) AS v; |
v
|
{"a": 1, "b": null, "c": 2} |
A second false clause, on the JSON_SET row only
The JSON_SET row promises NULL for one further case the server does not
give it: "or the optional path fails to find an object". A path that
finds nothing leaves the document alone and hands it back; NULL comes
only from a NULL json_doc or a NULL path.
SELECT JSON_SET('{"a":1}', '$.b.c', 2) AS v; |
v
|
{"a": 1} |
SELECT JSON_SET('[1]', '$[0].x', 2) AS v; |
v
|
[1]
|
For contrast, the two arguments that do produce NULL:
SELECT JSON_SET(NULL, '$.a', 1) AS v; |
v
|
NULL
|
SELECT JSON_SET('{"a":1}', NULL, 1) AS v; |
v
|
NULL |
The wording that is right
JSON_INSERT's row (topic 368) is accurate and is the model the other
four should follow: *"returning the resulting document or NULL if either
of the json_doc or path arguments are null"*.
The four rows to correct in scripts/fill_help_tables.sql are topics 356
(JSON_ARRAY_APPEND), 357 (JSON_ARRAY_INSERT), 386 (JSON_REPLACE) and 389
(JSON_SET). Topic 389 needs the second clause removed as well as the
first corrected.
Affected versions
The four help rows have carried this wording since the functions
were documented.
Verified on 10.11 only (10.11.19-MariaDB-debug, commit 1dab253482d).
Other branches were not tested.
Note
Found while auditing the JSON functions against their documented
contracts. The code behaviour is pinned and correct -
func_json_invalid.result:360-362 records
JSON_SET('{"a":1}', '$.a', NULL) -> {"a": null}. |
Attachments
Issue Links
- split from
-
MDEV-40642 Project "JSON Phoenix" - redundant computation elimination
-
- In Review
-