title: Check if a Postgres composite field is null/empty
body: <p>With <a href="http://www.postgresql.org/docs/9.2/static/rowtypes.html">postgres composite types</a> you can basically build a field with the structure being defined as another table. I have the composite field called "recipient" of type "person". This recipient field is often left empty in my specific scenario. What is the correct way to check if a composite field is empty. I tried:</p>
  
  <pre><code>select * from bla where recipient is not null
  select * from bla where recipient is null
  select * from bla where recipient = null
  select * from bla where recipient != null
  </code></pre>
  
  <p>In all of these cases, it doesn't return anything. So how do you correctly check if a composite value is empty or not?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>After some more reading, it looks like this is my problem:</p>
  
  <blockquote>
    <p>One may think that <code>!(x IS NULL) = x IS NOT NULL</code> is true in all cases. But there is an exception - composite types. When one field of a composite value is <code>NULL</code> and another field is <code>NOT NULL</code>, then result of both operators is false. <code>IS NULL</code> is true, only when all fields are <code>NULL</code>. <code>IS NOT NULL</code> is true, only when all fields are <code>NOT NULL</code>. For any case in between, then both operators return false.</p>
  </blockquote>
  
  <p>I do have some fields that are null, and others that are not. I was hoping that the field would be considered to be NOT NULL, if any item in the composite field is not null... not when ALL of them are not null. Is there any way around this other than checking each field?</p>