-
Notifications
You must be signed in to change notification settings - Fork 411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Connection.copy_records_to_table() fails on NUMERIC type #157
Comments
FWIW, I experience the same problem (Postgres 9.5.6 Python 3.6). |
I've done some digging here. I believe the root cause is the fact that the numeric codec is implemented as text protocol only (not binary). COPY IN requires all the data be encoded as binary. So the resolution of this would be changing/adding a binary codec for numeric (but then it is likely playing whack-a-mole, since it will be the next type that is only implemented as text causing a problem). It would be nice to get a better error message. Ideally, there would be a way to pass As far as I can tell that would somehow mean |
Searching through to find which types (that are likely to be used) would cause a problem, and we have:
Money looks relatively easy to implement (see: https://github.com/postgres/postgres/blob/master/src/backend/utils/adt/cash.c) it seems like just an int64 encoding. MAC address also looks relatively straight forward (see: https://github.com/postgres/postgres/blob/master/src/backend/utils/adt/mac.c#L161). Numeric is a little more involved (see: https://github.com/postgres/postgres/blob/master/src/backend/utils/adt/numeric.c#L858) Hopefully this is a starting point for someone. |
A potential problem with implementing this is how to handle display scale
I think that ndigits, weight and sign can all be round-tripped via the Decimal type, but I'm not sure how dscale would be handled inside Python. |
I think a starting point for
Main thing missing is working out what |
…odec. COPY .. FROM .. (FORMAT binary) currently requires that all data is encoded in binary format. Hence, we need to check if we have appropriate codecs for all columns before initiating CopyIn. Issue: #157.
I added a check to raise a better error message when a binary format encode is unavailable. |
As for the |
Can we close this issue now? |
I just retested the issue using current sources from master branch. Now it raises this error:
So, it is still impossible to use |
There are two outstanding issues here: lack of binary codec for |
macaddr not implemented. |
uvloop?: yes
It seems that
NUMERIC
values are not packed correctly for PGCOPY binary stream. I tried passingint
,float
andDecimal
values and got the same errorinsufficient data left in message
. Here is my example:Here is the traceback:
The text was updated successfully, but these errors were encountered: