使用Psycopg3复制跨服务器的表格
I'm working from and example in the psycopg3 documentation to copy a table from one database to another:
dsn_src = 'postgresql:///dev_db'
dsn_tgt = 'postgresql:///prod_test'
with psycopg.connect(dsn_src) as conn1, psycopg.connect(dsn_tgt) as conn2:
with conn1.cursor().copy("COPY sample TO STDOUT (FORMAT BINARY)") as copy1:
with conn2.cursor().copy("COPY sample FROM STDIN (FORMAT BINARY)") as copy2:
for data in copy1:
copy2.write(data)
在以下错误中运行此错误
QueryCanceled: COPY from stdin failed: error from Python: TypeError - can't write memoryview
CONTEXT: COPY sample, line 1
,源和目标架构是相同的,如文档所建议,如果格式规范(格式二进制)
被删除。
是否有解决此 MemoryView
错误的方法?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
猜测您正在使用
psycopg3
< = 3.0.11。将其固定在3.0.12 per 发行说明。我以3.0.11运行代码,如您所示,它失败了。我升级到3.0.13,它起作用了。Guessing you are using
psycopg3
<= 3.0.11. This was fixed in 3.0.12 per Release Notes. I ran the code in 3.0.11 and it failed as you showed. I upgraded to 3.0.13 and it worked.