1

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)?

1
  • 2
    When you consider the SQL meaning of NULL as no value, its meaning in equality operations is a little odd, however there are cases where <=> make sense. Some JOINs will be have rather differently with <=> rather than =. I'd keep to using <=> as an exceptional case rather than the default. Commented Jun 21, 2019 at 0:00

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

It probably also worth mentioning that there is a standardised operator IS DISTINCT FROM that does the same.
@zerkms I think you should add your comment as an answer, since that should be the right way of phrasing the predicate.
0
a = b -- Always NULL (which is usually treated as False) if either is NULL a <=> b -- True if _both_ are NULL 

If both columns are declared NOT NULL, there is no use to use <=>.

In almost all other cases, your logic is not going to care.

I almost never see anyone using <=>.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.