Post by o***@yahoo.com.arI want to share with you an investigations I made related to the SQL
weakness and interesting characteristics of this language on database
www.dbtheoryinpractice.com
I wouldn't call this "problems" but rather "possible pitfalls". Here are a
few comments...
If you have "v comparison NULL", then this will evaluate to "unknown". In
WHERE clauses, this "unknown" is interpreted like "false" (but it is not
the same as "false"). Thus, if you have "a.amount > ALL ( SELECT ... )",
the whole predicate will evaluate to "unknown" (if at least one row in the
subselect is NULL) after you applied the expansion for the ALL quantifier,
which will finally be interpreted like "false" and discard the row. Hence,
the only possible option for any database management system adhering to the
SQL standard is to return the empty set for your example. I would call
this a "user error" or a bad design choice made when developing the SQL
standard. (But the whole treatment of NULLs is rather convoluted in SQL.)
The INTERSECT example is indeed strange at a first glance. But the question
is how "unknown" comparisons are treated in the case of INTERSECT. (I
don't know for sure and I'm too lazy to look it up in SQL:2003 right now.)
If "NULL = xxx" is treated like "true" for set operations (as it is done in
CHECK constraints), then the results are correct and we have a user error -
again - if you expect a different result. Your reformulated query assumes
that "unknown" for set comparisons is treated like "false" as is done in
the WHERE clause. If this assumption is not correct, then the reformulated
query is simply not semantically equivalent.
The 3rd example is mostly a database design issue, as I gathered from the
initial paragraph.
--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany