You'll see that I created another issue report.
As you might guess, I'm starting to look at using inserttable() here :)
Now, I have a question and possibly another issue with inserttable().
I called Adapt().adapt() to handle None/strings/bytes/list, and pass a list of
the adapted results to inserttable(). This seemed to work fine, except for
timestamp values, which were failed during COPY since it was sending their
repr():
| sendto(3, "d\0\0\0005datetime.datetime(2021, 6, 19, 14, 57, 0,
58906)\nd\0\0\0\7\\.\nc\0\0\0\4", 67, MSG_NOSIGNAL, NULL, 0) = 67
| recvfrom(3, "E\0\0\0\377SERROR\0VERROR\0C22007\0Minvalid input syntax for
type timestamp with time zone: \"datetime.datetime(2021...
The timestamp isn't being stringified during adaptation:
| @classmethod
| def _adapt_date(cls, v):
| """Adapt a date parameter."""
| if not v:
| return None
| if isinstance(v, basestring) and v.lower() in cls._date_literals:
| return Literal(v)
| return v
Inserttable handles None, bytes, unicode, int, long, but then the timestamp
values falls through and gets repr()d here:
else {
PyObject* s = PyObject_Repr(item);
const char* t = PyStr_AsString(s);
The docs say:
| The rows values may contain string, integer, long or double (real) values.
If it's really intended to only handle those, then I guess it should call
PyFloat_Check() and error if the type isn't handled.
Alternately, should inserttable have an additional branch for PyDate_Check() ?
Or should its "else" branch use PyObject_Str instead of Repr ? When using
query(), adapt() returns the value itself, which is then stringified when
format_query() does command %= tuple(literals)
So maybe inserttable should do the same ?
--
Justin
_______________________________________________
PyGreSQL mailing list
[email protected]
https://mail.vex.net/mailman/listinfo/pygresql