postgresql

Export PostgreSQL database table header and data to CSV file

Introduction#

From Adminer management tool it’s has export to csv file option for mysql database But not available for postgresql database. Here I will show the command to export CSV for postgresql database.

Export PostgreSQL table to csv with header for some column(s)

COPY products(is_public, title, discount) TO 'D:\csv_backup\products_db.csv' DELIMITER ',' CSV HEADER;    

COPY categories(name) TO 'D:\csv_backup\categories_db.csv' DELIMITER ',' CSV HEADER;

Full table backup to csv with header

COPY products TO 'D:\csv_backup\products_db.csv' DELIMITER ',' CSV HEADER;    

COPY categories TO 'D:\csv_backup\categories_db.csv' DELIMITER ',' CSV HEADER;

copy from query

copy (select oid,relname from pg_class limit 5) to stdout;

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow