Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL - true/false query returning different on two servers

Tags:

sql

mysql

Confused on this one.

Same version of MySQL running on both servers. (built from exact same rpm's) - somewhere along the line some developer changed something...

Server 1:

mysql> select ( not 1 = 2 );

0
1 row in set (0.00 sec)

Server 2:

mysql> select ( not 1 = 2 );

1
1 row in set (0.00 sec)

Both servers:

mysql> sHOW VARIABLES LIKE 'version';

| version       | 5.6.12 |
like image 203
user3068015 Avatar asked Dec 04 '13 23:12

user3068015


1 Answers

You should check the HIGH_NOT_PRECEDENCE operator.

The official documentation states:

The precedence of the NOT operator is such that expressions such as NOT a BETWEEN b AND c are parsed as NOT (a BETWEEN b AND c). In some older versions of MySQL, the expression was parsed as (NOT a) BETWEEN b AND c. The old higher-precedence behavior can be obtained by enabling the HIGH_NOT_PRECEDENCE SQL mode.

Fiddle to test this behaviour here.

By the way, I would recommend to compare x != y rather than using not (x = y).

like image 87
Mosty Mostacho Avatar answered Nov 02 '22 19:11

Mosty Mostacho