Last active
October 30, 2020 06:24
-
-
Save yolabingo/62401318f526a48bcf59c103b9cd8327 to your computer and use it in GitHub Desktop.
separate a pg_dump file into individual tables
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
# first `mkdir tables` | |
dump_file = 'DUMPFILE.sql' | |
with open(dump_file, 'r') as sql: | |
table = None | |
for line in sql.readlines(): | |
if line.startswith('COPY public.'): | |
t = line.split()[1] | |
print(f"opening {t}") | |
table = open(f"tables/{t}", 'w') | |
if table: | |
table.write(line) | |
if line.strip() == '\.': | |
print('closing table') | |
table.close() | |
table = None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment