Search code examples
mysqlnullmariadbcomparison-operators

When not to use <=> instead of = in MariaDB/MySQL?


Is there any reason to use = instead of <=> in MariaDB/MySQL? It seems that the = operator is only desirable if the null is desirable for result of the expression.

Are there any consequences of replacing every = with <=>? Even if both operands can never be null (for which the behaviour should remain the exact same)?


Solution

  • First of all, the meaning of NULL is quite unclear. There are many articles in the Internet about how people interpret it.

    Therefore, using <=> could just add to the confusion and you risk than other developers may not understand it well. It strongly deviates from the standard behavior most people expect from queries. I would suggest you avoid it unless there are strong reasons why to use it.