2


Running the query ...

SELECT !(!0), ! !0, !!0 AS WTF;

in MySQL yields the following output ...

-------------------------
  !(!0) |  ! !0  |  WTF  
-------------------------
     0  |    0    |  1     # <- What's going on here?

I can't seem to find anything in the Docs that would explain this. Can you?

Charles
  • 48,924
  • 13
  • 96
  • 136
famagusta
  • 67
  • 6

1 Answers1

4

That's a known bug in mysql regarding operator parsing.

Mat
  • 188,820
  • 38
  • 367
  • 383
  • As a workaround you should use `NOT` instead of `!`. It's functionally equivalent, but it will avoid that bug because it forces you to put spaces between multiple operators, for example: `SELECT NOT (NOT 0), NOT NOT 0, NOT NOT 0 AS WTF;` – Ike Walker Apr 02 '11 at 18:23
  • Thanks Mat! @Ike Walker Not quite, the precedence of both `NOT` and `!` only happens to be the same when SQL mode [HIGH_NOT_PRECEDENCE](http://dev.mysql.com/doc/refman/5.1/en/server-sql-mode.html#sqlmode_high_not_precedence) is enabled! – famagusta Apr 02 '11 at 18:29
  • btw, I did the "!!" -> "not not" conversion to find that bug report in google :-) – Mat Apr 02 '11 at 18:30