Export PostgreSQL to CSV
Dump files or
psql output.
Free PostgreSQL to CSV converter. Upload a pg_dump .sql file or paste psql query output — aligned table, pipe-separated or CSV format. Handles standard SQL quoting and all psql output modes. Runs in your browser.
Native PostgreSQL CSV export commands
Use these when you have direct database access — faster and simpler than this tool for large exports.
How to export PostgreSQL to CSV
Two input modes — pick what you have available.
pg_dump file mode
Upload a .sql file generated by pg_dump. CSVShift parses INSERT statements with PostgreSQL's standard quoting — double-quote identifiers, '' escaped strings, BOOLEAN values and NULL. Each row in the INSERT becomes a CSV row.
psql CLI output mode
Copy output from any psql format and paste it here. CSVShift auto-detects the format: aligned table (default, with col | col2 and ----+---- separators), unaligned (-A flag), CSV output (\pset format csv), or tab-separated (-F '\t'). Footer lines like "(2 rows)" are stripped automatically.
Download RFC 4180 CSV
Download the resulting CSV with UTF-8 BOM encoding, or copy to clipboard. Opens correctly in Excel, Google Sheets and any database import tool without encoding issues.
When do you need to export PostgreSQL to CSV?
Common situations where a CSV export is necessary.
Data analysis in Excel or Sheets
PostgreSQL query results that need pivot tables, charts or manual review in a spreadsheet — paste the psql output directly into CSVShift for instant conversion without needing server file access.
Database migration
Exporting a PostgreSQL table as CSV for re-import into MySQL, SQLite or another system. CSV avoids SQL dialect incompatibilities in direct dump conversion.
Sharing data without DB access
Paste query output from a psql session, convert to CSV here, and share the spreadsheet with non-technical stakeholders who don't have database credentials.
pg_dump backup analysis
Analyse a PostgreSQL backup's INSERT data in Excel to verify data integrity, check row counts, or audit specific values — without needing to restore the database.
Related CSV tools
Other free converters on CSVShift you might need.
PostgreSQL data parsed
in your browser. No upload.
CSVShift parses pg_dump files and psql output entirely in JavaScript. Your database data is never transmitted to any server. The parser handles PostgreSQL's standard SQL string escaping ('' not backslash) and correctly identifies NULL, BOOLEAN, NUMERIC and TEXT values.
4 psql output formats
Standard SQL quoting
Footer stripping
Free, no conditions
How do I export PostgreSQL to CSV?
\copy table TO 'file.csv' WITH (FORMAT csv, HEADER true); — writes to your local machine. For a browser-based option, run the query in psql, copy the output, switch to CLI Output mode in CSVShift and paste it.How do I use \copy in psql to export CSV?
\copy (SELECT * FROM table) TO '/local/path/file.csv' WITH (FORMAT csv, HEADER true); — the backslash \copy writes to the file on your local machine, not the PostgreSQL server. Works with any remote or cloud PostgreSQL instance without needing server file system access.How do I export a PostgreSQL query to CSV?
\copy (SELECT col1, col2 FROM table WHERE condition ORDER BY col1) TO 'file.csv' CSV HEADER;. Any valid SELECT query works as the source. Alternatively, use \pset format csv then run the query to get CSV output in the terminal.