Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python psycopg更新不';行不通_Python_Postgresql_Psycopg2 - Fatal编程技术网

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