title: Bulk insert to postgresql with prepared statement(s)
body: <p>I'm using libpq (but I am potentially be ready to switch to other library)</p>
  
  <p>I have a bunch of similar INSERT queries I want to make, they are different only in values between them.</p>
  
  <p>I'd like to use prepared statements to avoid issues with escaping fields.
  I also want to send them in one batch so that I don't spend roundtrip for each query.</p>
  
  <p>I know only this options:</p>
  
  <p>Use <code>PQExec()</code> with multiple insert, divided by semicolon: 
    This doesn't allow prepared statements, so I need to create query dynamically</p>
  
  <p>Use <code>PQexecParams()</code> for each query separately:
    This has problems of multiple roundtrips spent</p>
  
  <p>Use <code>PQprepare()</code> + <code>PQExecPrepared()</code> for each query separately:
    Same problem as previous</p>
  
  <p>Use <code>PQexecParams()</code> for single query with several inserted lines e.g <code>INSERT INTO tablename (a,b,c) VALUES ("A", "B", "C"), ("aa", "bb", "cc")</code>:
    It's a bit better than the first option, because it allow not to escape arguments, but still requires building query dynamically (and the worst part you'll have to increment number of arguments ($1, $2, $3) for first line but ($4,$5,$6) for the second, etc)</p>
  
  <p>So, how to avoid these drawbacks?</p>