Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Abhay Joshi sychonet

🎯
Focusing
View GitHub Profile
@sychonet
sychonet / export_csv_pg.sh
Last active Dec 5, 2017
Shell script to export individual table data in csv from a database in PostgreSQL
View export_csv_pg.sh
#!/bin/bash
# Shell script to export individual table data in csv from a database in PostgreSQL.
SCHEMA=""
DB=""
psql -h host -p 5432 -U username -Atc "select tablename from pg_tables where schemaname='$SCHEMA'" $DB |\
while read TBL; do
psql -h host -p 5432 -U username -c "COPY $SCHEMA.$TBL TO STDOUT WITH CSV" $DB > $TBL.csv
done
You can’t perform that action at this time.