How to export data to a CSV file from a PostgreSQL database together with table headings

H

How Can We Help?

How to export data to a CSV file from a PostgreSQL database together with table headings

  1. Type in the following command in postgres using the command line:
    copy products to ‘/home/user/products.csv’ delimiters ‘,’ CSV HEADER

    • products = (Database Table)
    • ‘/home/user/products.csv‘ = (Location where to save the csv file)
    • You need to have write permissions to write the file to the filesystem with the postgres user
    • CSV HEADER – This is the feature that let’s you export the table headings as well, please note that the HEADER argument has only been introduced in Postgres 8.1

How to import a CSV file into a postgresql?

About the author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

About Author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

Follow Me