Skip to content

Instantly share code, notes, and snippets.

@prykon
Last active October 22, 2021 16:12
Show Gist options
  • Save prykon/3a7f4c5336d09a6068bf16a289f01455 to your computer and use it in GitHub Desktop.
Save prykon/3a7f4c5336d09a6068bf16a289f01455 to your computer and use it in GitHub Desktop.
This script splits your .sql files into files that are roughly under 100 MB.
filename = '' # Add filename here
import os
if os.path.isdir('split_queries'):
print('The \'split_folder\' folder already exists. Splitting query...')
pass
else:
print('Creating \'split_queries\' folder...')
os.mkdir('split_queries')
content = open( filename ).read()
queries = content.split("\nINSERT INTO")
output = ''
n = 0
j = 0
for i in range(0, len(queries)):
if ( n >= 350 ):
j = j+1
new_file = open('split_queries/%02d.sql' % j, 'w')
new_file.write( output )
new_file.close()
n = 0
output = ''
print( '%02d.sql done.' % j )
if ( i == 0 ):
output += queries[i]
else:
output += 'INSERT INTO' + queries[i]
n = n+1
print('All done.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment