title: Export an array into a CSV-file in PL/pgSQL
body: <p>I have a function, which RETURNS SETOF text[]. Sample result of this function:</p>
  
  <pre><code>{080213806381,"personal data1","question 1",answer1,"question 2",answer2,"question 3","answer 3"}
  {080213806382,"personal data1","question 1",answer1,"question 2",answer2,"question 3","answer 3"}
  </code></pre>
  
  <p>I'm forming each row with a statement like:</p>
  
  <pre><code>resultRow := array_append(resultRow, fetchedRow.data::text);
  </code></pre>
  
  <p>and then:</p>
  
  <pre><code>RETURN NEXT resultRow;
  </code></pre>
  
  <p>And here's my COPY command:</p>
  
  <pre><code>COPY( 
  SELECT myFunction()
  ) TO 'D:\test_output.csv' WITH (FORMAT 'csv', DELIMITER E',', HEADER false)
  </code></pre>
  
  <p>And I have a couple of problems:</p>
  
  <ol>
  <li>Regardless the fact that values are appended to the array in the same way, some of them are double-quoted and some of them are not. This somehow depends on a presence of space character in a value. Look, for instance, at the 1st element of the array or at the answer2 and "answer 3" in each row. I want some unified behavior.</li>
  <li>After exporting in to CSV with COPY command I'm getting the same rows with all these curly braces at the beginning and the end. I dont want them in CSV.</li>
  </ol>
  
  <p>What can I do to solve these issues?</p>