If you are using PostgreSQL 8.2 or later, use this for CSV:
psql -c "COPY (<select query>) TO STDOUT WITH CSV"
and this is TSV with corresponding NULL:
psql -c "COPY (<select query>) TO STDOUT WITH NULL AS ''"
The CSV form will correctly indicate any fields containing the double quote character. For more information and options for COPY, see the PostgreSQL documentation for your specific version.
Matthew Wood Jun 29 '11 at 2:55 a.m. 2011-06-29 14:55
source share