Skip to content

Instantly share code, notes, and snippets.

@jackeyGao
Created August 25, 2016 02:40
Show Gist options
  • Select an option

  • Save jackeyGao/db862c6066d86f602826658b88895005 to your computer and use it in GitHub Desktop.

Select an option

Save jackeyGao/db862c6066d86f602826658b88895005 to your computer and use it in GitHub Desktop.
DELETE TO INSERT
with open('del.sql', 'r') as f:
insert = ""
for i in f.readlines():
if i.startswith('### DELETE FROM'):
insert = insert.strip(',') + ';'
if insert != ';':
print insert
insert = "INSERT INTO"
insert += i.split('FROM')[1].strip('\n')
if i.startswith('### WHERE'):
insert += " SELECT "
if i.startswith('### @'):
insert += i.split('=')[1].strip('\n') + ','
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment