psql2csv

Run PostgreSQL queries and export results as CSV files

brewmacoslinux
Try with needOr install directly
Source

About

Run a query in psql and output the result as CSV

Commands

psql2csv

Examples

Export a simple query result to CSV$ psql2csv -h localhost -U username -d mydatabase -c "SELECT * FROM users" > output.csv
Export query with custom delimiter and output file$ psql2csv -h localhost -U postgres -d mydb -c "SELECT id, name, email FROM customers WHERE active = true" -d '|' -o customers.csv
Export large table using connection string$ psql2csv postgresql://user:password@localhost:5432/database -c "SELECT * FROM large_table LIMIT 10000" > results.csv