Last active
January 25, 2018 12:33
-
-
Save rhanka/2f11a235482e3f9bb81dbbd4157461f6 to your computer and use it in GitHub Desktop.
Dirty pg_restore + perl conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#get all schemas of the dump | |
schemas=`cat $1 | docker exec -i postgres pg_restore -l | grep SCHEMA | sed 's/^.*\s//' | sort | uniq` | |
for schema in $schemas | |
do echo $schema | |
for table in `cat $1 | docker exec -i postgres pg_restore -l | egrep "TABLE $schema" |sed "s/.*TABLE $schema //;s/ $schema//' | sort | uniq ` | |
do echo $table | |
cat $1 | docker exec -i postgres pg_restore -t $table | perl -e 'while(<>){if (/^\\.\s*$/) {$dump=0} if ($dump==1) {s/\\N//g;print} if (/COPY/){$dump=1;s/.*\((.*)\).*/$1/;s/,\s*/\t/g;print}}' > $table.csv | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment