title: PQgetvalue() strips spaces from result of string_agg()
body: <p>I have a GNU C++ project that uses the PostgreSQL API and for some reason, it strips spaces from the result of a certain query. Other environments (<code>psql</code> and pgAdmin) don't. The query is:</p>
  
  <pre><code>SELECT string_agg(my_varchar, ', ') FROM my table;
  </code></pre>
  
  <p>Notice the space after the comma in the delimiter. Instead of <code>1046976, 1046977</code> being returned by <code>PQgetvalue()</code>, I get <code>1046976,1046977</code>. Just for kicks, I tried changing the delimiter to silly things like <code>string_agg(my_varchar, ',:) '</code> and <code>string_agg(my_varchar, ', :)'</code>. It <em>doesn't</em> strip the space if the space is in the <em>middle</em> of the delimiter.</p>
  
  <p>Again, I don't have this problem if I do the same queries in db browsers like <code>psql</code> and pgAdmin; they don't strip the space in any of those queries.</p>
  
  <p>Yes, I considered the possibility that because the columns from which they extract are <code>varchar</code>s, but the data are 7-bit integers, the engine might be confused. I changed the query to something that is truly a <code>varchar</code>, but the spaces were still stripped.</p>
  
  <p>Looking at <a href="https://www.postgresql.org/docs/9.4/static/functions-aggregate.html" rel="nofollow noreferrer">https://www.postgresql.org/docs/9.4/static/functions-aggregate.html</a>, I see that <code>string_agg()</code> expects its arguments to be <code>text</code>s or <code>bytea</code>s. Well, I never got an error, but to be sure, I tried <code>string_agg(my_varchar::text, ', '::text)</code>. It didn't make a difference.</p>
  
  <p>I don't know a great deal about this API, but it doesn't appear to connect to the db with any options, so I don't think there's much to say about the configuration.</p>
  
  <p>I'm running this in GNU C++ v4.9.2 on Debian 8.10. The PostgreSQL engine and API are 9.4.</p>