Als je met mysqldump een dump van je data maakt kun je deze na bewerking met onderstaand Python script inlezen in PostgreSQL
#!/usr/bin/python
import sys
if len(sys.argv) != 2:
print "Usage " + sys.argv[0] + " input_bestand"
print "Usage " + sys.argv[0] + " input_bestand.sql"
quit()
print "Maak van te voren de ins directory leeg want dit script doet een append aan de file"
f_in = open(sys.argv[1],"r")
for line in f_in:
#line = line.rstrip()
#line mag niet gestript worden vanwege document tabel
if line.find("INSERT INTO") != -1 :
fields = line.split('`')
table_name = fields[1]
#if table_name != "log_message" :
# continue
print "Table name = " + table_name
f_out = open("ins/" + table_name + ".sql","a")
new_line = line.replace('`','',2)
new_line = new_line.replace("\\'","''")
values = new_line.split('),(')
if len(values) == 1 :
f_out.write(values[0])
else :
f_out.write(values[0] + ");\n")
for i in range(len(values)) :
if i == 0 :
continue
#print "i = " + str(i) + " value = [" + values[i] + "]\n"
if i == len(values) -1 :
f_out.write("INSERT INTO " + table_name + " VALUES (" + values[i] )
else :
f_out.write("INSERT INTO " + table_name + " VALUES (" + values[i] + ");\n")
f_out.close()
f_in.close()