Output Query as CSV (PostgreSQL)

From ben.goodacre.name/tech

Jump to: navigation, search

Use the following to output a query a CSV. Offending characters like new-lines and conmmas are automatically stripped:

COPY ( select * from table ) to '/var/tmp/query.csv' with csv header;

OR the following also outputs as CSV but offending characters are not stripped:

psql -F, -A -q -h 1.1.1.1 db user
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox