0

So suppose I made an sqlite3 database in which I made a table

c.execute("CREATE TABLE tablnam(thing TEXT, thing2 TEXT, thing3 TEXT)")

then I made a list

list = ["a","b","c"]

How would I go about inserting that one list into tablnam in just one row. I've tried

c.execute("insert into this values(?)",list)

but it returns Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: parameters are of unsupported type

so to clarify for those who don't understand: I want to insert a lists values, into ONE row in an sqlite3 table in python thx!

1 Answer 1

2

Well buddy, that can't work, you are trying to put a list where a text belongs. Try doing it that way:

c.execute("INSERT INTO tablenam(thing, thing2, thing3) VALUES (?, ?, ?)",list[0], list[1], list[2])

Differences to your suggestions:

  • I am putting a single string into each text field
  • you can only insert exactly three list items per row.
  • I've changed your SQL Syntax to contain tablenam and also put in the column names
  • changed the SQL style: keywords in allcaps

Note that you can't (and shouldn't) put an entire list into a single row in a DB. If you have to do something along those lines, have a look at foreign keys.

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.