[英]insert list into one row in python3 sqlite3
So suppose I made an sqlite3 database in which I made a table 因此,假设我创建了一个sqlite3数据库,其中创建了一个表
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. 我该如何将那一个列表插入tablnam的一行中。 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
但它返回
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! 因此,对于那些不了解的人可以进行澄清:我想将列表值插入python thx的sqlite3表的ONE行中!
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: 与您的建议有所不同:
tablenam
and also put in the column names tablenam
并也将其放在列名中 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.
如果您必须按照这些原则进行操作,请查看外键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.