By using NULL
you can distinguish between “put no data” and “put empty data”.
Some more differences:
-
A
LENGTH
ofNULL
isNULL
, aLENGTH
of an empty string is0
. -
NULL
s are sorted before the empty strings. -
COUNT(message)
will count empty strings but notNULL
s -
You can search for an empty string using a bound variable but not for a
NULL
. This query:SELECT * FROM mytable WHERE mytext = ?
will never match a
NULL
inmytext
, whatever value you pass from the client. To matchNULL
s, you’ll have to use other query:SELECT * FROM mytable WHERE mytext IS NULL