python - psql cast parse error during cursor.fetchall() -
i have python code queries psql , returns batch of results using cursor.fetchall()
. throws exception , fails process if casting fails, due bad data in db. exception:
file "/usr/local/lib/python2.7/site-packages/psycopg2cffi/_impl/cursor.py", line 377, in fetchall return [self._build_row() _ in xrange(size)] file "/usr/local/lib/python2.7/site-packages/psycopg2cffi/_impl/cursor.py", line 891, in _build_row self._casts[i], val, length, self) file "/usr/local/lib/python2.7/site-packages/psycopg2cffi/_impl/typecasts.py", line 71, in typecast return caster.cast(value, cursor, length) file "/usr/local/lib/python2.7/site-packages/psycopg2cffi/_impl/typecasts.py", line 39, in cast return self.caster(value, length, cursor) file "/usr/local/lib/python2.7/site-packages/psycopg2cffi/_impl/typecasts.py", line 311, in parse_date raise dataerror("bad datetime: '%s'" % bytes_to_ascii(value)) dataerror: bad datetime: '32014-03-03'
is there way tell caster ignore error , parse string instead of failing entire batch?
you can "hack" parser of psycopg2cffi
return date objects strings instead:
if in code can see registration of date parser, can replace serializer of date in code.
import psycopg2cffi psycopg2cffi._impl.typecasts._default_type('date', [1082], psycopg2cffi._impl.typecasts.parse_string)
of course can done, every type.
Comments
Post a Comment