title: POSTGRESQL unable to compare null columns
body: <p>Following is my SQL query:</p>
  
  <pre><code>update table 
  set unit_id = T1.unit_id_temp from
         (select case when unit_id4 is not null then unit_id4
          when unit_id3 is not null then unit_id3
          when unit_id2 is not null then unit_id2
          when unit_id1 is not null then unit_id1
          else unit_id
          end as unit_id_temp,
          unit_id1,unit_id2,unit_id3,unit_id4
          from   table)  T1
  where table.unit_id4  = T1.unit_id4
  and   table.unit_id3  = T1.unit_id3
  and   table.unit_id2  = T1.unit_id2  
  and   table.unit_id1  = T1.unit_id1 
  </code></pre>
  
  <p>From the above query i am unable to compare columns when they are NULL, as the condition returns false.</p>
  
  <p>For Example:
  when unit_id4 is null ,
       table.unit_id4 = T1.unit_id4 returns False.</p>
  
  <p>Hence my update fails whenever either of the columns contain NULL vallues.</p>
  
  <p>I tried using is not distinct from, it does not work. Throws the following error:</p>
  
  <p>UPDATE - 0 rows, 0.000 secs]  [Code: 0, SQL State: 42601]  ERROR: syntax error at or near "distinct"</p>