Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.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/psycopg2中迭代结果集时更新项_Python_Postgresql_Python 3.x_Psycopg2 - Fatal编程技术网

在Python/psycopg2中迭代结果集时更新项

在Python/psycopg2中迭代结果集时更新项,python,postgresql,python-3.x,psycopg2,Python,Postgresql,Python 3.x,Psycopg2,我在数据库中有一个实体列表,我检索并迭代这些实体,如下所示: import psycopg2 cur.execute("select * from items") rows = cur.fetchall() for x in rows: # some stuff 我希望能够更新循环中实体上的一些字段 for x in rows: # some stuff if some_condition: curr.execute("update i

我在数据库中有一个实体列表,我检索并迭代这些实体,如下所示:

  import psycopg2

  cur.execute("select * from items")
  rows = cur.fetchall()
  for x in rows:
    # some stuff
我希望能够更新循环中实体上的一些字段

  for x in rows:
    # some stuff
    if some_condition:
      curr.execute("update items set....

是否可以在循环内部执行此操作?如果没有,解决办法是什么?循环后立即更新所有事务对我不起作用。

我认为光标将保留事务,因此您必须在每个循环中处理这些事务。在sql中完成所有操作。@ClodoaldoNeto,mysql?@Kuqa不,仅使用sql而不是Python。