{"id":2472,"date":"2015-07-21T03:25:14","date_gmt":"2015-07-21T03:25:14","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=2472"},"modified":"2015-07-21T03:25:14","modified_gmt":"2015-07-21T03:25:14","slug":"rethinkdb-is-null-in-a-where-clause-filter","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/rethinkdb-is-null-in-a-where-clause-filter\/","title":{"rendered":"RethinkDB &#8220;IS NULL&#8221; in a where clause filter"},"content":{"rendered":"<p>I find the syntax for RethinkDB filtering a little unintuitive &#8211; if this was actually Javascript, you might expect to see &#8220;row[&#8216;Query&#8217;]&#8221;. I expect this allows them to instrument the queries more easily, although considering they are supposedly translating this into an intermediate language, this doesn&#8217;t seem necessary.<\/p>\n<p>To do equality, non-equality, and so on, there are several functions available (ne \/ eq \/ gt \/ lt). I suspect that the reason for this is that the getter function for a column always returns an object &#8211; so it can&#8217;t be &#8220;equal&#8221; to null. This is likely a Builder pattern that lets them lazy-execute results; if this database goes the direction of Oracle&#8217;s optimizer it will also provide opportunities for query rewriting.<\/p>\n<p>The key is, using Javascript operators will be syntactically correct, but will not work. Unfortunately the RethinkDB editor does not warn you about this, or auto-correct them.<\/p>\n<pre lang=\"Javascript\">\nr.db('performance')\n.table('query_timings')\n.filter(\n  function(d){ \n    return d('Query').ne(null) \n  }) \n<\/pre>\n<p>Hopefully in the future we&#8217;ll also see ES6 functions, to make this more compact.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I find the syntax for RethinkDB filtering a little unintuitive &#8211; if this was actually Javascript, you might expect to see &#8220;row[&#8216;Query&#8217;]&#8221;. I expect this allows them to instrument the queries more easily, although considering they are supposedly translating this into an intermediate language, this doesn&#8217;t seem necessary. To do equality, non-equality, and so on, &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.garysieling.com\/blog\/rethinkdb-is-null-in-a-where-clause-filter\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;RethinkDB &#8220;IS NULL&#8221; in a where clause filter&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[157,160,302,462,466,523],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/2472"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=2472"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/2472\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=2472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=2472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=2472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}