tags:

views:

43

answers:

3

I am wondering how to create or export CSV file from SQL? Is tehre any function for that similar as pgsql2shp????? I would appreciate your ideas, tip or solutions.

+5  A: 
COPY tablename TO STDOUT CSV

http://www.postgresql.org/docs/8.4/static/sql-copy.html

vartec
+1  A: 

You can give this a try. But i believe there may be some syntax changes depending on the version.

COPY (SELECT foo,bar FROM whatever) TO ‘/tmp/dump.csv’ WITH CSV HEADER
gruntled
I got this message: ERROR: could not open file "/dump.csv" for writing: Permission deniedWhat should i do now?Btw, instead of the query above i wrote:COPY (SELECT * FROM table1) TO '/dump.csv' WITH CSV HEADER because proposed path does not exist.
Z77
Anyone, please????
Z77
Ok. I found out that problem was in path. So I changed path to:'C:/Program Files/PostgreSQL/8.4/data/test.csv' and it works now. Obvoiusly some folders has restrictions.
Z77
A: 

If you use pgAdmin, you can export any query you run to a CSV file.

Federico Cristina