0

I have a PostgreSQL database running in a docker container. I used the below command to get a dump file of the Postgres database - "docker exec -t your-db-container pg_dumpall -c -U postgres > dump_date +%d-%m-%Y"_"%H_%M_%S.sql". Since it's a docker volume , the database doesn't store on the machine to use psql COPY command and such.

I have multiple tables with different headers. I need to convert the dump file into a CSV file with the headers of the table. Can be a single or multiple CSV files.

Any other way of directly getting the CSV files from the docker container database will also be appreciated.

PS: I'm a beginner in this area and would really appreciate a detailed solution

2
  • One might use the COPY command to export data as CSV.
    – mustaccio
    Jul 16, 2022 at 13:47
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Jul 18, 2022 at 13:31

2 Answers 2

0

You have to use 'COPY' command,try this:

COPY (SELECT * from table) To '/path/output.csv' With CSV;
1
  • I'm not able to use this as the database isn't storing on the machine. Jul 19, 2022 at 6:29
-1

Using pg_dump with the -t flag could provide a plain text output for a table and you can increase the tables you need by adding that flag as much as needed. On the other hand getting a CSV output is only available via psql flag --csv.

So you can try

psql -d your_db -c 'select * from your_table' --csv 

for your need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.