exporting quoted CSV data from a query

From: "George Pavlov" <gpavlov(at)mynewplace(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: exporting quoted CSV data from a query
Date: 2006-05-08 19:26:48
Message-ID: 8C5B026B51B6854CBE88121DBF097A8611FAC3@ehost010-33.exch010.intermedia.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Is there a way to export the output of an arbitrary SQL query to a
quoted CSV file?

It seems that the COPY command can do that for regular tables (COPY foo
TO STDOUT WITH CSV QUOTE AS '"') but not for a query result. I could
create temp tables in a script but it seems that there should be a
simpler alternative.

The command-line psql can obviously be used with an arbitrary query, but
seems to fail on the quoting part--am I missing some option to psql that
would put quotes around fields that contain the quote character,
newlines, etc.?

What I am looking for is essentially a command-line alternative to the
pgAdmin export's "quoting" options.

George

Responses

Browse pgsql-general by date

  From Date Subject
Next Message George Pavlov 2006-05-08 19:37:46 Re: Using the REPLACE command to replace all vowels
Previous Message Karl O. Pinc 2006-05-08 19:11:39 pg_restore duplicate key violations