我正在使用 python3、postgress 10 和 Psycopg2 来查询多条记录,就像这样
import psycopg2
conn = psycopg2.connect(<my connection string>)
with conn:
with conn.cursor() as cur:
cur.execute('select id,field1 from table1')
for id, field1 from cur.fetchall():
print(id,field1)
#todo: how up update field1 to be f(field1) where f is an arbitrary python function
我的问题是:如何更新我正在读取的行的值并将 field1 的值设置为一些基于 python 的任意计算
编辑:目的是更新表中的行