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()
1
  • please take a good look at stackoverflow.com/questions/3653462/… and it would be better to store the data in their own column or as json Commented Oct 12, 2020 at 10:32

1 Answer 1

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)])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.