export table to csv on postgres

Luba Weissmann picture Luba Weissmann · Dec 19, 2013 · Viewed 25.8k times · Source

How can I export a table to .csv in Postgres, when I'm not superuser and can't use the copy command?

I can still import the data to postgres with "import" button on the right click, but no export option.

Answer

marvinorez picture marvinorez · Dec 19, 2013

Use psql and redirect stream to file:

psql -U <USER> -d <DB_NAME> -c "COPY <YOUR_TABLE> TO stdout DELIMITER ',' CSV HEADER;" > file.csv