title: Postgresql batch insert or ignore
body: <p>I have the responsibility of switching our code from sqlite to postgres.  One of the queries I  am having trouble with is copied below.</p>
  
  <pre><code>INSERT INTO group_phones(group_id, phone_name)
  SELECT g.id, p.name 
  FROM phones AS p, groups as g
  WHERE g.id IN ($add_groups) AND p.name IN ($phones);
  </code></pre>
  
  <p>The problem arises when there is a duplicate record.  In this table the combination of both values must be unique.  I have used a few plpgsql functions in other places to do update-or-insert operations, but in this case I can do several inserts at once.  I am not sure how to write a stored routine for this.  Thanks for all the help from all the sql gurus out there!</p>