psycopg,事务和多个游标 [英] psycopg, transactions and multiple cursors

查看:49
本文介绍了psycopg,事务和多个游标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哦不!这是我和交易再次:)


我不确定这是否是对psycopg的限制或

postgresql。当我在交易中使用多个游标时,在交易开始时插入的记录

对于那些后来的交易是不可见的(使用不同的交易)光标)。


附件是一个简化的例子(除了'有点生硬,我知道)

我想要的做。实际上,不同的游标有时会在不同的线程中运行,或者它们是嵌套的,这就是为什么我不能使用相同的游标来支持所有游标的原因。查询。


我再做一些傻事还是这个错误(在什么?)?

这里有人对这个问题的解决方案有一些想法吗?什么是

你的信用卡号码(不,不能回答!)?我将学到什么?

时间?


问候,


Alban Hertroys,

MAG Productions。

Oh no! It''s me and transactions again :)

I''m not really sure whether this is a limitation of psycopg or
postgresql. When I use multiple cursors in a transaction, the records
inserted at the start of the transaction aren''t visible to those later
on in that transaction (using a different cursor).

Attached is a simplified example (the except''s are a bit blunt, I know)
of what I''m trying to do. In reality, the different cursors are
sometimes run in differeent threads, or they''re nested, which is why I
can''t use the same cursor for all queries.

Am I doing something silly again or is this a bug (in what?)? Does
anybody here have some ideas about a solution for this problem? What is
your credit card number (No, don''t answer that!)? What will I learn this
time?

Regards,

Alban Hertroys,
MAG Productions.

推荐答案

Alban Hertroys写道:
Alban Hertroys wrote:
附件是一个简化的例子(除了我知道,这有点生硬了。
我想做什么。实际上,不同的游标有时会在不同的线程中运行,或者它们是嵌套的,这就是为什么我不能对所有查询使用相同的游标。


我想实际的错误信息也很有用(Doh!):

python transaction.py
Attached is a simplified example (the except''s are a bit blunt, I know)
of what I''m trying to do. In reality, the different cursors are
sometimes run in differeent threads, or they''re nested, which is why I
can''t use the same cursor for all queries.
I suppose the actual error message would be useful too (Doh!):
python transaction.py



{''id'':1L}

回溯(最近一次呼叫最后一次):

文件" transaction.py",第40行,在?

cursor2.execute(" INSERT INTO y(x_id)VALUES(%s)"%row [" id"])

psycopg.IntegrityError:错误:插入或更新在表格y上违反

外键约束


{''id'': 1L}
Traceback (most recent call last):
File "transaction.py", line 40, in ?
cursor2.execute("INSERT INTO y (x_id) VALUES (%s)" % row["id"])
psycopg.IntegrityError: ERROR: insert or update on table "y" violates
foreign key constraint "


1"

DETAIL:键(x_id)=(1)在表中不存在x。


INSERT INTO y(x_id)VALUES(1)
1"
DETAIL: Key (x_id)=(1) is not present in table "x".

INSERT INTO y (x_id) VALUES (1)


> psycopg.IntegrityError:错误:在表y上插入或更新违反
> psycopg.IntegrityError: ERROR: insert or update on table "y" violates
外键约束


这篇关于psycopg,事务和多个游标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆