Bug #117834 Double negation on booleans incorrectly returns negated value
Description:
Using a double negation on booleans returns the negated boolean value instead of the original boolean value. This bug is present in version 9.2 and in earlier versions 5-8+.
How to repeat:
SELECT !!1, !!0; -- expected: {1, 0}; actual: {0, 1}
The expected result is produced when:
(1) Parenthesis is used:
SELECT !(!1), !(!0); -- {1, 0}
However, based on the precedence description of the NOT operator in the documentation (https://dev.mysql.com/doc/refman/9.2/en/logical-operators.html#operator_not), it is unexpected that using parenthesis would affect the result of the query evaluation.
This is because !!1 should evaluate to !(!1) and likewise, !!0 should evaluate to !(!0).
(2) Using NOT instead of !
SELECT NOT NOT 1, NOT NOT 0; -- {1, 0}
SELECT NOT(NOT 1), NOT(NOT 0) -- {1, 0}
This is unexpected because NOT is semantically equivalent to !.
It is mentioned in the documentation (https://dev.mysql.com/doc/refman/9.2/en/logical-operators.html#operator_not) that:
> The ! operator is a nonstandard extension, and is deprecated; expect it to be removed in a future version of MySQL. Applications, where necessary, should be adjusted to use the standard SQL NOT operator instead.
However, the use of ! is still documented and supported in version 9.20, thus this bug should still be relevant.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.039 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.
Description: Using a double negation on booleans returns the negated boolean value instead of the original boolean value. This bug is present in version 9.2 and in earlier versions 5-8+. How to repeat: SELECT !!1, !!0; -- expected: {1, 0}; actual: {0, 1} The expected result is produced when: (1) Parenthesis is used: SELECT !(!1), !(!0); -- {1, 0} However, based on the precedence description of the NOT operator in the documentation (https://dev.mysql.com/doc/refman/9.2/en/logical-operators.html#operator_not), it is unexpected that using parenthesis would affect the result of the query evaluation. This is because !!1 should evaluate to !(!1) and likewise, !!0 should evaluate to !(!0). (2) Using NOT instead of ! SELECT NOT NOT 1, NOT NOT 0; -- {1, 0} SELECT NOT(NOT 1), NOT(NOT 0) -- {1, 0} This is unexpected because NOT is semantically equivalent to !. It is mentioned in the documentation (https://dev.mysql.com/doc/refman/9.2/en/logical-operators.html#operator_not) that: > The ! operator is a nonstandard extension, and is deprecated; expect it to be removed in a future version of MySQL. Applications, where necessary, should be adjusted to use the standard SQL NOT operator instead. However, the use of ! is still documented and supported in version 9.20, thus this bug should still be relevant.