title: Don't update column if update value is null
body: <p>I have a query like this (in a function):</p>
  
  <pre><code>UPDATE some_table SET
    column_1 = param_1,
    column_2 = param_2,
    column_3 = param_3,
    column_4 = param_4,
    column_5 = param_5
  WHERE id = some_id;
  </code></pre>
  
  <p>Where <code>param_x</code> is a parameter of my function. Is there a way to NOT update those columns, for which the param is <code>NULL</code>? For example - if <code>param_4</code> and <code>param_5</code> are <code>NULL</code>, then update only the first three columns and leave old values for <code>column_4</code> and <code>column_5</code>.</p>
  
  <p>The way I am doing it now is:</p>
  
  <pre><code>SELECT * INTO temp_row FROM some_table WHERE id = some_id;
  
  UPDATE some_table SET
    column_1 = COALESCE(param_1, temp_row.column_1),
    column_2 = COALESCE(param_2, temp_row.column_2),
    column_3 = COALESCE(param_3, temp_row.column_3),
    column_4 = COALESCE(param_4, temp_row.column_4),
    column_5 = COALESCE(param_5, temp_row.column_5)
  WHERE id = some_id;
  </code></pre>
  
  <p>Is there a better way?</p>