rspec/rules/S2527/tsql/rule.adoc

38 lines
846 B
Plaintext
Raw Normal View History

2021-01-27 13:42:22 +01:00
In a Zen-like manner, "NULL" is never equal to anything, even itself. Therefore comparisons using equality operators will always return ``++False++``, even when the value actually ``++IS NULL++``.
2020-06-30 12:48:07 +02:00
2021-02-02 15:02:10 +01:00
2021-01-27 13:42:22 +01:00
For that reason, comparison operators should never be used to make comparisons with ``++NULL++``; ``++IS NULL++`` and ``++IS NOT NULL++`` should be used instead.
2020-06-30 12:48:07 +02:00
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,sql]
2020-06-30 12:48:07 +02:00
----
UPDATE books
SET title = 'unknown'
WHERE title = NULL -- Noncompliant
----
== Compliant Solution
2022-02-04 17:28:24 +01:00
[source,sql]
2020-06-30 12:48:07 +02:00
----
UPDATE books
SET title = 'unknown'
WHERE title IS NULL
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]