title: Postgresql NOT NULL AND <> '' vs NOT NULL OR <> ''
body: <p>I have read lots about the <strong>difference between NOT NULL vs &lt;>''</strong></p>
  
  <p>The best explanation I found for it was in:</p>
  
  <p><a href="https://www.postgresql.org/message-id/AANLkTilEsUTIeUkZCX9Vc14kciFiuvFBRRE-yen4K_Zi@mail.gmail.com" rel="nofollow">https://www.postgresql.org/message-id/AANLkTilEsUTIeUkZCX9Vc14kciFiuvFBRRE-yen4K_Zi@mail.gmail.com</a> which states:</p>
  
  <blockquote>
    <p>NULL means the question hasn't been answered yet, thus there is no
    answer, there may be an answer once it is provided so you can't really
    say the answer is empty. Empty would mean the answer has been given and
    the answer is empty.</p>
  </blockquote>
  
  <p>For the table that I am working on, I was trying to filter results for <strong>valid postcodes only</strong> (postcode is a VARCHAR in this specific table), I tried the following:</p>
  
  <pre><code>SELECT postcode FROM customer_table_1 
  WHERE postcode IS NOT NULL OR postcode &lt;&gt; '';
  </code></pre>
  
  <p>However this gives some blank postcodes in my results. Breaking this down ...</p>
  
  <pre><code>SELECT postcode FROM customer_table_1 
  WHERE postcode IS NOT NULL;
  </code></pre>
  
  <p>gives some blank postcodes whereas </p>
  
  <pre><code>SELECT postcode FROM customer_table_1 
  WHERE postcode &lt;&gt;'';
  </code></pre>
  
  <p>only gives valid postcodes in the result. Therefore the IS NOT NULL part of the query isn't doing what I thought it was.</p>
  
  <p>As part of a more complicated query, I have previously used:</p>
  
  <pre><code>SELECT postcode FROM customer_table_1 
  WHERE postcode IS NOT NULL AND postcode &lt;&gt; '';
  </code></pre>
  
  <p>and have achieved the desired result. However I have always thought it should be </p>
  
  <pre><code>SELECT postcode FROM customer_table_1 
  WHERE postcode IS NOT NULL OR postcode &lt;&gt; '';
  </code></pre>
  
  <p><strong>Because I am looking for all records that have a valid postcode (i.e. are NOT NULL or NOT empty strings) should these not be connected with an OR statement rather than an AND? I'm not looking for postcodes that are both NULL and empty strings, just one or the other.</strong></p>
  
  <p>Apologies if this is a stupid question, using an AND doesn't seem logical to me and I don't want to blindly do something without understanding the process behind the result. I thought I fully understood the difference between NOT NULL and &lt;>'' but as with most things Postgres related, the more I delve into it the more I realize I don't actually know!</p>