Bug #102601 nested nullif of json values fails
Submitted: 15 Feb 2021 13:42 Modified: 16 Feb 2021 9:12
Reporter: Dave Pullin (Basic Quality Contributor) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: JSON Severity:S3 (Non-critical)
Version:5.7.31, 5.7.33 OS:CentOS (CentOS Linux release 7.6.1810 (Core))
Assigned to: CPU Architecture:Any

[15 Feb 2021 13:42] Dave Pullin
Description:
nullif(nullif(json_object(),"anything"),json_object()) 

should return null. it returns "{}" 

select nullif(nullif(json_object(),json_array()),json_object());

mysql> select  nullif(nullif(json_object(),"anything"),json_object()) as nested ,  nullif(json_object(),json_object()) as single;
+--------+--------+
| nested | single |
+--------+--------+
| {}     | NULL   |
+--------+--------+
1 row in set, 1 warning (0.00 sec)

mysql> show warnings;
+---------+------+-------------------------------------------------------------------------+
| Level   | Code | Message                                                                 |
+---------+------+-------------------------------------------------------------------------+
| Warning | 3156 | Invalid JSON value for CAST to INTEGER from column json_object at row 1 |
+---------+------+-------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql>

(the problem is NOT the "anything". The same problem occurs if that value is clearly a json: for example:

mysql> select nullif(nullif(json_object(),json_array()),json_object());
+----------------------------------------------------------+
| nullif(nullif(json_object(),json_array()),json_object()) |
+----------------------------------------------------------+
| {}                                                       |
+----------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> show warnings;
+---------+------+-------------------------------------------------------------------------+
| Level   | Code | Message                                                                 |
+---------+------+-------------------------------------------------------------------------+
| Warning | 3156 | Invalid JSON value for CAST to INTEGER from column json_object at row 1 |
+---------+------+-------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> 

How to repeat:
select  nullif(nullif(json_object(),"anything"),json_object()) as nested ,  nullif(json_object(),json_object()) as single;
show warnings;
select nullif(nullif(json_object(),json_array()),json_object());
show warnings;
[16 Feb 2021 9:12] MySQL Verification Team
Hello Dave,

Thank you for the report and test case.
Verified as described.

regards,
Umesh