How to export data from PostgreSQL table to csv file

We can use COPY statement to export data from PosrgreSQL table to csv file.

Step1: Login to PostgreSQL shell

Step2: Change the database

#\c db

Where db need to be replaced with the database name.

Step3: Execute the export query.

#COPY table TO 'csv-location' DELIMITER ',' CSV HEADER;

Where table need to be replaced with the name of the table and csv-location need to be replaced with the full path of output file.

That's all…

Leave a Reply