Oracle can't find empty strings
2008-10-25
Sometimes you just seem to find these wonderfull design descissions that has corner cases that the desgner should have, but didn't anticipate. Like oracles' NULL handling:
> create table foo (bar varchar(5), fie varchar(5));
> insert into foo (bar, fie) values ('', 'tom');
> insert into foo (bar, fie) values (null, 'null');
> select fie from foo where bar not in ('x', 'y');
Gives no rows
> select fie from foo where bar = '';
Gives no rows
> select fie from foo where bar is null;
null, 'tom'
null, 'null'
Python has a similar problem with strings versus characters (characters are considered one-character strings), with similar problems.
>>> type("foo")
<type 'str'>
>>> type("a")
<type 'str'>
>>> type("a"[0])
<type 'str'>
>>> "a"[0] == "a"
True
>>> "a"[0][0][0] == "a"
True
So, what's the lession to learn from this? Never ever treat a value of one type (e.g. Varchar) as the same as a value of another type (e.g. NullType).