1

How do I insert these 2 lists into different SQL columns of the same table

a = [1,2,3]
b = [4,5,6]

This is the way to insert one list into a column

query = "INSERT INTO tableName (col1) VALUES (%s)"
cursor.executemany(query, [(r,) for r in a])

I can't seem to figure out how to insert both the lists into the table, I want list a to be in one column and list b to be in other column

2 Answers 2

2
query = "INSERT INTO tableName (col1, col2) values (%s, %s)"
cursor.executemany(query, [(x, y) for x, y in zip(a, b)])
Sign up to request clarification or add additional context in comments.

Comments

0

I would do something like this:

query = "INSERT INTO sometable (somecol, somecol2) values (something, something)"
cursor.executemany(query, [(v, x) for v, x in zip(t, h)])

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.