title: How to upsert multiple rows in PostgreSQL
body: <p>I'm trying to write a query like this in PostgreSQL 9.5.2:</p>
  
  <pre><code>INSERT INTO a (id, x)
      SELECT id, x FROM b
  ON CONFLICT (id) DO UPDATE
      SET x = b.x
      WHERE b.y &lt; 100
  </code></pre>
  
  <p>but I get <code>ERROR: missing FROM-clause entry for table "b"</code>. I must be missing something basic, but how do I refer to the row being inserted in the UPDATE clause? Or is there some other way?</p>