Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Abhay Joshi sychonet

🎯
Focusing
Block or report user

Report or block sychonet

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
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.