Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In the usual case where the LHS term is a simple variable or expression, there is no difference between <code>NOT x IS NULL</code> and <code>x IS NOT NULL</code>. The optimizer will treat the two identically.</p> <p>However, in full SQL, the LHS term is not limited to being a simple variable or expression; in the formal grammar, the LHS is a <code>&lt;row value predicand&gt;</code>:</p> <h3>SQL/Foundation - ISO/IEC 9075-2:2003</h3> <blockquote> <p>§8.7 <code>&lt;null predicate&gt;</code> (p395)</p> <p>Specify a test for a null value.</p> <pre><code>&lt;null predicate&gt; ::= &lt;row value predicand&gt; &lt;null predicate part 2&gt; &lt;null predicate part 2&gt; ::= IS [ NOT ] NULL </code></pre> </blockquote> <p>And chasing through the grammar, you find that:</p> <blockquote> <p>§7.2 <code>&lt;row value expression&gt;</code> (p296)</p> <p>Specify a row value.</p> <p>[...]</p> <pre><code>&lt;row value predicand&gt; ::= &lt;row value special case&gt; | &lt;row value constructor predicand&gt; &lt;row value special case&gt; ::= &lt;nonparenthesized value expression primary&gt; </code></pre> </blockquote> <p>And:</p> <blockquote> <p>§7.1 <code>&lt;row value constructor&gt;</code> (p293)</p> <p>Specify a value or list of values to be constructed into a row or partial row.</p> <pre><code>&lt;row value constructor&gt; ::= &lt;common value expression&gt; | &lt;boolean value expression&gt; | &lt;explicit row value constructor&gt; </code></pre> <p>[...]</p> <pre><code>&lt;row value constructor predicand&gt; ::= &lt;common value expression&gt; | &lt;boolean predicand&gt; | &lt;explicit row value constructor&gt; </code></pre> </blockquote> <p>And so it goes on. (Chasing anything through the SQL standard is hard work. You can find a heavily hyperlinked version of the standard at <a href="http://savage.net.au/SQL/" rel="noreferrer">http://savage.net.au/SQL/</a>.)</p> <p>However, as you may guess from the mention of 'row value', you can have multiple simple expressions combined on the LHS to form a 'row value constructor predicand'. And then there is a difference between the two forms.</p> <p>Conceptually, you have:</p> <pre><code>(val1, val2, val3) IS NOT NULL </code></pre> <p>vs</p> <pre><code>NOT (val1, val2, val3) IS NULL </code></pre> <p>Now, in the first case, you get TRUE if each of val1, val2 and val3 is not NULL. In the second case, you get TRUE if any one of val1, val2, val3 is not NULL. So, there are circumstances where the two operations are not identical.</p> <p>However, as I said up front, for the usual case of a simple column or expression, there is no difference between the two.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload