Bug #116703 `JSON_VALID` has inconsistent behavior for `NULL`
Description:
The document (https://dev.mysql.com/doc/refman/5.7/en/json-attribute-functions.html#function_json-valid) said the `JSON_VALID` function should return `NULL` for `NULL` argument. However, this behavior is not consistent when the argument is a column or a literal NULL.
For a column, it returns 0 instead of NULL.
```
mysql> create table t(col int);
Query OK, 0 rows affected (0.02 sec)
mysql> insert into t values (NULL);
Query OK, 1 row affected (0.01 sec)
mysql> select json_valid(t.col) from t;
+-------------------+
| json_valid(t.col) |
+-------------------+
| 0 |
+-------------------+
1 row in set (0.00 sec)
```
For a NULL literal, it returns NULL
```
mysql> select json_valid(NULL);
+------------------+
| json_valid(NULL) |
+------------------+
| NULL |
+------------------+
1 row in set (0.00 sec)
```
How to repeat:
For a column, it returns 0 instead of NULL.
```
mysql> create table t(col int);
Query OK, 0 rows affected (0.02 sec)
mysql> insert into t values (NULL);
Query OK, 1 row affected (0.01 sec)
mysql> select json_valid(t.col) from t;
+-------------------+
| json_valid(t.col) |
+-------------------+
| 0 |
+-------------------+
1 row in set (0.00 sec)
```
For a NULL literal, it returns NULL
```
mysql> select json_valid(NULL);
+------------------+
| json_valid(NULL) |
+------------------+
| NULL |
+------------------+
1 row in set (0.00 sec)
```
Suggested fix:
Make the result consistent. It'd be better to return NULL for `json_valid(col)` when the column is a `NULL`.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.040 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.