Python psycopg更新不';行不通
我试图使用Python psycopg更新不';行不通,python,postgresql,psycopg2,Python,Postgresql,Psycopg2,我试图使用psycopg更新postgres数据库中的一些行,但它什么也不做,脚本运行时没有错误,但数据库没有更改 import psycopg2 conn = psycopg2.connect("dbname=timetrack user=n") cur = conn.cursor() cur.execute("select id, extract(epoch from begin_time) as b, extract(epoch from end_time) as e from acti
psycopg
更新postgres数据库中的一些行,但它什么也不做,脚本运行时没有错误,但数据库没有更改
import psycopg2
conn = psycopg2.connect("dbname=timetrack user=n")
cur = conn.cursor()
cur.execute("select id, extract(epoch from begin_time) as b, extract(epoch from end_time) as e from activities;")
rows = cur.fetchall()
m = 10 ** 6
for i in range(0, len(rows)):
row = rows[i]
print(row)
cur.execute("update activities set begin=(%s), \"end\"=(%s) where id=(%s);",
(row[0] * m, row[1] * m, row[2]))
conn.commit()
cur.close()
conn.close()
事实证明,我在为row变量编制索引时犯了一个错误。我想在字符串中设置begin-to-begin、end-to-end和id-to-id。然而,我最终设置了begintoid、end tobegin和id tobegin。Postgres找不到任何要更新的行,因为ID错误,所以它什么也没做。你说的“它什么都没做”是什么意思?什么是“它”?哪一行的行为与您预期的不同?你期待什么?实际发生了什么?可能是因为您正在使用
epoch from end\u time
作为id
到update
?