Python has clear separation between True
, False
and None
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
$ ipython
Python 3.8.0 (default, Nov 13 2019, 13:19:53)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.18.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: True == True
Out[1]: True
In [2]: True == False
Out[2]: False
In [3]: False == False
Out[3]: True
In [4]: False == True
Out[4]: False
In [5]: False == None
Out[5]: False
In [6]: None == None
Out[6]: True
In [7]: None == True
Out[7]: False
|
Now look at the similar one from SQL (postgres)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
$ psql -U postgres
psql (12.1)
Type "help" for help.
postgres=# select TRUE = TRUE;
?column?
----------
t
(1 row)
postgres=# select TRUE = FALSE;
?column?
----------
f
(1 row)
postgres=# select TRUE = NULL;
?column?
----------
(1 row)
postgres=# select FALSE = NULL;
?column?
----------
(1 row)
postgres=# select NULL = NULL;
?column?
----------
(1 row)
|
As you might have guessed, psql returns t
for True and f
for False
But when compared to NULL, it does not return either t
or f
In SQL, NULL
is unknown.
When you think about it, two unknowns are not equal.
That is why when we compare NULL
s - we do not get t
(As we get when comparing None
s in python)
Thanks to Mo Binni for teaching me this via the ZTM DB course on Udemy
You should check out this course