title: PostgreSQL 9.4 - Comparing NULL values
body: <p>Under normal conditions, comparing a <code>NULL</code> value to any other value results in another <code>NULL</code> value.</p>
  
  <pre><code>SELECT NULL = NULL;
  </code></pre>
  
  <p><strong>Returns <code>NULL</code></strong></p>
  
  <hr>
  
  <p>This holds (mostly) true when comparing arbitrary rows, as explained in <a href="http://www.postgresql.org/docs/current/static/functions-comparisons.html" rel="noreferrer">the documentation, 9.23.5. Row Constructor Comparison</a>:</p>
  
  <pre><code>SELECT ROW(1, NULL, 'baz text') = ROW(1, NULL, 'baz text'); 
  </code></pre>
  
  <p><strong>Returns <code>NULL</code></strong></p>
  
  <hr>
  
  <p>However, when comparing well defined composite types, <code>NULL</code> values are treated as equal.</p>
  
  <pre><code>CREATE TYPE test_type AS (
      foo INTEGER,
      bar BIGINT,
      baz TEXT
  );
  
  SELECT (1, NULL, 'baz text')::test_type = (1, NULL, 'baz text')::test_type;
  </code></pre>
  
  <p><strong>Returns <code>TRUE</code></strong></p>
  
  <p>This behavior seems to be undocumented (I have looked and found no reference to the behavior).</p>
  
  <p>I would like to use this behavior to implement some business rules and want to make sure it is safe to do so.</p>
  
  <ol>
  <li>Is this consistent with any SQL specification?</li>
  <li>Is it <em>likely</em> this will change in the future?</li>
  </ol>