title: Batch Conditional INSERT INTO statement in Postgres
body: <p>I want to <code>UPSERT</code> in Postgres, but my version is below 9.5 so I cannot use <code>ON CONFILICT</code>. I found something like this:</p>
  
  <pre><code>UPDATE table SET field='C', field2='Z' WHERE id=3;
  INSERT INTO table (id, field, field2)
         SELECT 3, 'C', 'Z'
         WHERE NOT EXISTS (SELECT 1 FROM table WHERE id=3);
  </code></pre>
  
  <p>But how can I do this with <strong>batch</strong> values?
  This statement might can express what I want to do (It cannot work):</p>
  
  <pre><code>INSERT INTO result_data (HOST_ID, RESOURCE_TYPE, TIMESTAMP, UPPER, LOWER, AVG) 
      (values ("xxxxx", "cpu", 1544313900, 80, 70, 75), ("aaaaaa", "cpu", 1544314000, 80, 70, 75))
      AS result2(HOST_ID, RESOURCE_TYPE, TIMESTAMP, UPPER, LOWER, AVG) 
      WHERE NOT EXISTS(SELECT 1 FROM result_data WHERE result2.HOST_ID = result_data.HOST_ID);
  </code></pre>