title: export postgres requests result into csv file (using shell script), each request result in a csv column
body: <p>I have a shell script containing many Postgres (9.3) requests, I want to export the result in a CSV file (every request result in a corresponding column) I found the \pset option and I'm searching how to use it .. what I have now is all results in the first column.</p>
  <p>that's a part of the script :</p>
  <pre><code>\pset
  
  \o ${EXP_TEMP}
  
  SELECT  cast((xpath('/ECMFSpec/Package/Fields/ProviderInfo/Name/text()',
  WFS.mdm_metadata.document)::text[])[1]::text as VARCHAR) FROM mdm_metadata ;
  
  
  
  SELECT  cast((xpath('/ECMFSpec/Series/Fields/ProviderInfo/Identifier/Id/text()',
  WFS.mdm_metadata.document)::text[])[1]::text as VARCHAR) FROM mdm_metadata ;
  
  SELECT cast((xpath('/ECMFSpec/Series/Fields/ProviderInfo/Identifier/Id/text()',WFS.mdm_metadata.document)
   ::text[])[1]::text as VARCHAR) FROM mdm_metadata ;
  
  SELECT  cast((xpath('ECMFSpec/Series/Fields/AssetName/text()',
  WFS.mdm_metadata.document)::text[])[1]::text as VARCHAR) FROM mdm_metadata ;
  
  SELECT  to_char(cast((xpath('/ECMFSpec/Series/Title/Fields/Rights/LicensingWindowStart/text()',
  WFS.mdm_metadata.document)::text[])[1]::text as DATE),'dd/MM/yyyy HH:MI:SS') FROM mdm_metadata ;
  
  SELECT  to_char(cast((xpath('/ECMFSpec/Series/Title/Fields/Rights/LicensingWindowEnd/text()',
  WFS.mdm_metadata.document)::text[])[1]::text as  DATE),'dd/MM/yyyy HH:MI:SS') FROM mdm_metadata ;
  
  SELECT  to_char(cast((xpath('/ECMFSpec/Package/Title/Fields/Rights/AvailabilityWindowEnd/text()',
  WFS.mdm_metadata.document)::text[])[1]::text as  DATE),'dd/MM/yyyy HH:MI:SS') FROM mdm_metadata ;
  
  SELECT  cast((xpath('/ECMFSpec/Series/Poster[position()=1]/Fields/AssetName/text()',
  WFS.mdm_metadata.document)::text[])[1]::text as VARCHAR) FROM mdm_metadata ;
  
  SELECT  cast((xpath('/ECMFSpec/Series/Poster[position()=2]/Fields/AssetName/text()',
  WFS.mdm_metadata.document)::text[])[1]::text as VARCHAR) FROM mdm_metadata ;
  
  SELECT  cast((xpath('/ECMFSpec/Series/Poster[position()=5]/Fields/AssetName/text()',
  WFS.mdm_metadata.document)::text[])[1]::text as VARCHAR) FROM mdm_metadata ;
  EOF
  
           cat ${EXP_TEMP} | sed &quot;s/^\ //;s/\ *$//&quot; &gt; ${EXTRACT_FILE}
          sed -i '1iProviderId;TitleId;AssetName;LicensingWindowStart;LicensingWindowEnd;AvailabilityWindowEnd;ImageIds;MasterTitleStatus;CreationDate;Title;AssetType;MOTO;Smart Vision;CDN IPTV;CDN OTT' ${EXTRACT_FILE}
  </code></pre>