April 5, 2012

Is there a reason not to use <=> (null safe equals operator) in mysql instead of =?

Question by cellige

MySql provides a nice operator <=> that works with comparisons that could contain a null such as null <=> null or null <=> 5 etc giving back intuitive results as many programming languages. Where as the normal equals operator always just returns null, which catches many new MySql users such as myself awry.

Is there a reason MySql has both and not JUST the functionality in <=> ? Who really needs an operator that is effectively undefined with built in language types?

Answer by Starx

Is there a reason MySql has both and not JUST the functionality in <=>
?
The operators are completely different from each other.

<=> performs an equality comparison like the = operator, but returns 1 rather than NULL if both operands are NULL, and 0 rather than NULL if one operand is NULL.

Who really needs an operator that is effectively undefined with built
in language types?

This depends on case, just because you haven’t encountered such cases, does not mean nobody needs it.

...

Please fill the form - I will response as fast as I can!