Export Table to CSV file with header in PostgreSQL

1. Using psql

\copy table_name to 'filename.csv' csv header

2. Using SQL Query

COPY table_name TO 'file_name.csv' DELIMITER ',' CSV HEADER;

3. Using TablePlus

In TablePlus, right-click on the table name in the left sidebar and choose Export.... You can also select the table then navigate to menu File > Export… and choose CSV output.

Note that if you right-click on the data browser view, it will export only the current page of results, not the whole table.

Export Data


Need a good GUI tool for PostgreSQL? Check out TablePlus. It’s native, beautiful, and available for free.

Download TablePlus for Mac.

Not on Mac? Download TablePlus for Windows.

On Linux? Download TablePlus for Linux

Need a quick edit on the go? Download TablePlus for iOS.

TablePlus GUI Tool PostgreSQL