如何将python列表插入Postgres选项卡

2024-06-16 12:06:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图确定将python列表中的数据插入PostgreSQL表的最简单方法。

我的PostgreSQL表创建如下:

CREATE TABLE results(Id serial primary key, T0 timestamp, T1 real, T2 real, T3 real, T4 real, Total real, Result text);

我的python列表格式如下

ResultsList = ['2015-07-20 16:06:05', 0.16, 5.22, 5.81, 0.69, 11.90, 'OK']

我使用下面的python代码将列表写到结果表中

import psycopg2 as dbapi
con = dbapi.connect(database='xxx', user='xxx')
cur = con.cursor()
cur.execute("INSERT into results VALUES (%s);", (ResultsList),)
con.commit()

口译员指出以下错误:

Error not all arguments converted during string formatting
Process finished with exit code 0

如有任何线索将不胜感激。

谢谢:)


Tags: 数据方法id列表postgresqlcreatetableserial