title: Updating multiple rows with different primary key in one query in PostgreSQL?
body: <p>I have to update many columns in many rows in PostgreSQL 9.1. I'm currently doing it with many different <code>UPDATE</code> queries, each one that works on a different row (based on the primary key):</p>
  
  <pre><code>UPDATE mytable SET column_a = 12, column_b = 6 WHERE id = 1;
  UPDATE mytable SET column_a = 1, column_b = 45 WHERE id = 2;
  UPDATE mytable SET column_a = 56, column_b = 3 WHERE id = 3;
  </code></pre>
  
  <p>I have to do several thousands of these queries.</p>
  
  <p>Is there anyway I can "bulk update" lots of rows in one query in PostgreSQL? If you're using <code>INSERT</code>, you can insert multiple rows at once: (<code>INSERT INTO mytable (column_a, column_b) VALUES ( (12, 6), (1, 45) );</code>), Is there something like that for <code>UPDATE</code>?</p>
  
  <p>Something like:</p>
  
  <pre><code>UPDATE mytable SET (id, column_a, column_b) FROM VALUES ( (1, 12, 6), (2, 1, 45), (3, 56, 3), … )
  </code></pre>
  
  <p>??</p>
  
  <p>The important points is that each 'VALUE' will only update one row (based on the <code>WHERE id =</code>). Each row will have the same, fixed number of columns that need updating, but each row will have different values for each column, so <code>UPDATE mytable SET column_a = 12, column_b = 6 WHERE id IN (1, 2, 3);</code> won't work.</p>