Home Databases pgSql How to export data to a CSV file from a postgres database together with table headings?
 
 
 

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

PDF Print E-mail

Question: How to export data to a CSV file from a postgres database together with table headings?

 

Answer: 

  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?


+/-
+/- Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
Security Please input the anti-spam code that you can read in the image.
 

Go Daddy $7.49 .com Sale!