Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fallenstedt/5a0406a3c86e3e96cc2c609cef444e9f to your computer and use it in GitHub Desktop.
Save Fallenstedt/5a0406a3c86e3e96cc2c609cef444e9f to your computer and use it in GitHub Desktop.
Dump PostgreSQL Table in docker container as CSV file
CONTAINER="name"
DB="Db name"
TABLE="Table Name"
FILE="file.csv"
sudo docker exec -u postgres ${CONTAINER} psql -d ${DB} -c "COPY ${TABLE} TO STDOUT WITH CSV HEADER " > ${FILE}
# Copy csv to table
# sudo psql -h localhost -U root -d my_db -p 5432 -c "\COPY source_table TO '/home/user/source_table.csv' DELIMITER ',' CSV HEADER;"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment