0

I have a list of list values that I would like to add into mysql database.

tech = [1.0, 1.0, '', 0.92, 0.65, 1.0, 0.83, '', 0.5] hr = [1.0, 2.0, 1.5, 4.0, .83, 1.2]

mysql database has the same column names as the list variables. Can you guide me on how I can implement that?

I tried as below but getting an error "Not all parameters were used in the sql statement:

query = "INSERT INTO statvalues (tech, hr) VALUES (%s, %s)"
values = (tech, hr)
cursor.executemany(query,values)
cursor.close()
database.commit()
edcoder
  • 503
  • 1
  • 5
  • 19
  • please take a good look at https://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad and it would be better to store the data in their own column or as json – nbk Oct 12 '20 at 10:32

1 Answers1

0

Based on the answer on this link : MySql: Inserting python lists into a table , I was able to solve my issue

query = "INSERT INTO statvalues (tech, hr) values (%s, %s)"
cursor.executemany(query, [(x, y) for x, y in zip(techlist, hrlist)])
edcoder
  • 503
  • 1
  • 5
  • 19