title: Inserting integer array with postgresql in C (libpq)
body: <p>I'm trying to post an integer array into my postgresql database. I'm aware that I could format everything as a string and then send that string as one SQL command. However, I believe the PQexecParams function should also bring some help. However, I'm kind of lost as how to use it.</p>
  
  <pre><code>    //we need to convert the number into network byte order
      int val1 = 131;
      int val2 = 2342;
      int val3[5] = { 0, 7, 15, 31, 63 };
      //set the values to use
      const char *values[3] = { (char *) &amp;val1, (char *) &amp;val2, (char *) val3 };
      //calculate the lengths of each of the values
      int lengths[3] = { sizeof(val1), sizeof(val2), sizeof(val3) * 5 };
      //state which parameters are binary
      int binary[3] = { 1, 1, 1 };
  
      PGresult *res = PQexecParams(conn, "INSERT INTO family VALUES($1::int4, $2::int4, $3::INTEGER[])", 3, //number of parameters
              NULL, //ignore the Oid field
              values, //values to substitute $1 and $2
              lengths, //the lengths, in bytes, of each of the parameter values
              binary, //whether the values are binary or not
              0); //we want the result in text format
  </code></pre>
  
  <p>Yes this is copied from some tutorial.
  However this returns :</p>
  
  <pre><code> ERROR:  invalid array flags
  </code></pre>
  
  <p>Using a conventional method does work:</p>
  
  <pre><code>PQexec(conn, "INSERT INTO family VALUES (2432, 31, '{0,1,2,3,4,5}')");
  </code></pre>
  
  <p>Inserts data just fine, and I can read it out fine as well.</p>
  
  <p>Any help would be greatly appreciated! :)</p>