{"id":1613,"date":"2010-09-30T07:09:21","date_gmt":"2010-09-30T14:09:21","guid":{"rendered":"http:\/\/journal2.alanv.org\/?p=1613"},"modified":"2012-10-07T22:04:45","modified_gmt":"2012-10-08T02:04:45","slug":"null","status":"publish","type":"post","link":"https:\/\/journal2.alanv.org\/?p=1613","title":{"rendered":"null"},"content":{"rendered":"<p>Yesterday afternoon&#8217;s little bit of head scratching and debugging confusion comes to you courtesy of the fact that<\/p>\n<blockquote><p>SELECT * FROM my_table<br \/>\nWHERE my_id = iObject.my_id<\/p><\/blockquote>\n<p>does not do the expected thing when both <tt>my_id<\/tt> and <tt>iObject.my_id<\/tt> are <tt>null<\/tt>.<br \/>\nBecause apparently <tt>null = null<\/tt> and <tt>null &lt;&gt; null<\/tt> both evaluate to <tt>false<\/tt>, because any comparison involving <tt>null<\/tt> evaluates to <tt>false<\/tt>.<br \/>\n(<strong>Edit<\/strong>: As pointed out to me by many people, it should actually evaluate to <tt>null<\/tt>, but regardless, the effect is the same&#8230; the select statement does not get the rows you expect.)<\/p>\n<p>I guess it makes sense when you think about it (a lack of a value is not equal to the lack of a value, because there is no value, as opposed to C where <tt>null<\/tt> is just a pointer to <tt>0x0<\/tt> so a value comparison makes sense), but it&#8217;s still a surprising issue when you first come across it. Working around it involves the non-intuitive<\/p>\n<blockquote><p>SELECT * FROM my_table<br \/>\nWHERE (my_id IS NULL AND iObject.my_id IS NULL) OR my_id = iObject.my_id<\/p><\/blockquote>\n<p>It looks like MySql also provides the null-comparing operator <tt>&lt;=&gt;<\/tt> which will return equality even if both items are null. But it doesn&#8217;t look like Oracle does.<\/p>\n<p>Blah.<\/p>\n<p>On an unrelated note, I&#8217;ve redone the design of <a href=\"http:\/\/photos2.alanv.org\">photos<\/a>. Check it out if you haven&#8217;t yet, and let me know if things are broken or don&#8217;t work for you. :)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday afternoon&#8217;s little bit of head scratching and debugging confusion comes to you courtesy of the fact that SELECT * FROM my_table WHERE my_id = iObject.my_id does not do the expected thing when both my_id and iObject.my_id are null. Because &hellip; <a href=\"https:\/\/journal2.alanv.org\/?p=1613\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,11],"tags":[],"class_list":["post-1613","post","type-post","status-publish","format-standard","hentry","category-code","category-salesforce"],"_links":{"self":[{"href":"https:\/\/journal2.alanv.org\/index.php?rest_route=\/wp\/v2\/posts\/1613","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/journal2.alanv.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/journal2.alanv.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/journal2.alanv.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/journal2.alanv.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1613"}],"version-history":[{"count":0,"href":"https:\/\/journal2.alanv.org\/index.php?rest_route=\/wp\/v2\/posts\/1613\/revisions"}],"wp:attachment":[{"href":"https:\/\/journal2.alanv.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1613"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/journal2.alanv.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1613"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/journal2.alanv.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1613"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}