我希望通过Python向Postgres表中插入一组值:
这些值存储在一个列表中,例如:
new=
[
[gold, dresden, 1000, 24],
[silver, Cologne, 600, 42],
[gold, Aachen, 3000, 25]
]
这个表已经在Postgres中创建了,包括表头。我该如何进行插入操作?
db.execute("INSERT INTO B4_O (position, city, amount, score) VALUES (%s,%s,%s)", new)
db.commit
但是这个代码会报错:
在字符串格式化过程中并非所有参数都被转换
for item in new: ...
和db.execute(..., item)
或者尝试new[0]
? - jmunsch