how to signal EOF to psycopg2.copy_from()?
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 con开发者_开发问答dition. 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?
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.
精彩评论