psycopg,事务和多个游标

编程入门 行业动态 更新时间:2024-10-27 10:33:04
本文介绍了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,事务和多个游标

本文发布于:2023-10-24 09:54:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1523633.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   游标   事务   psycopg

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!