I want to generate dynamic insert statements using python script. I will be using the data from a csv file to get the inserts: so far this is what I am able to accomplish via google:
import csv
openFile = open('test.csv', 'r')
csvFile = csv.reader(openFile)
header = next(csvFile)
headers = map((lambda x: '`'+x+'`'), header)
insert = 'INSERT INTO Table (' + ", ".join(headers) + ") VALUES "
for row in csvFile:
values = map((lambda x: '"'+x+'"'), row)
print (insert +"("+ ", ".join(values) +");" )
openFile.close()
the insert statements should have single quotes only on strings and not on numbers.