如何向 psycopg2.copy_from() 发出 EOF 信号?
我正在尝试从一个(非 postgres)游标读取数据并使用结果来提供 psycopg2.copy_from()。除了 EOF 条件之外,我似乎一切正常。我的光标有一个包装器,可以将其变成类似文件的对象,并且在 read() 方法中我有:
row = self.readline()
if not row:
return ""
但这会导致 copy_from(cursor_as_file, 'cm_outgoing') 窒息
ERROR: invalid input syntax for integer: ""
CONTEXT: COPY cm_outgoing, line 533, column id: ""
这有点有意义,因为第一个cm_outgoing 中的字段是一个整数,并传递一个零长度字符串。我应该以不同的方式发出 EOF 信号吗?或者我还缺少其他东西吗?
I'm trying to read from one (non-postgres) cursor and use the results to feed psycopg2.copy_from(). I seem to have everything working fine, EXCEPT the EOF condition. I have a wrapper for my cursor that turns it into a file-like object, and in that read() method I have:
row = self.readline()
if not row:
return ""
But this causes the copy_from(cursor_as_file, 'cm_outgoing') to choke with
ERROR: invalid input syntax for integer: ""
CONTEXT: COPY cm_outgoing, line 533, column id: ""
This kinda makes sense, as the first field in cm_outgoing is an integer, and passing a zero-length string. Should I be signaling EOF differently? Or am I missing something else?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误发生在不同的地方。在另一点上,我的文件中有一个双换行符。我不确定为什么 copy_from() 没有在那里抱怨,但修复双换行符似乎已经解决了这个问题。
The error was in a different place. At another point, I had a double-newline in the file. I'm not sure why copy_from() didn't complain there, but fixing the double-newline seems to have taken care of this problem.