-
Notifications
You must be signed in to change notification settings - Fork 365
return NUMBER as int if possible, otherwise as decimal.Decimal #663
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
Comments
First, have you considered upgrading to python-oracledb which replaces cx_Oracle? That driver does effectively what you have in V2 automatically. I'd have to look at cx_Oracle again to see if that code is there, too -- but I would definitely recommend upgrading if you are able to do so! |
Thanks for the hint.
In cx_Oracle I found some int or float logic or an unconditional use of decimal.Decimal: python-cx_Oracle/src/cxoTransform.c Line 884 in 6766bca
|
Understood. In that case the second option is likely the best one -- but you can always run some tests to confirm! Note that the new driver uses similar logic. If you are looking for returning a decimal.Decimal instance for those numbers that require a decimal point and integers for those numbers that are pure integers (even though found in a column that may contain numbers with decimal points) then you will still require an output type handler. Since internally the value is fetched as a string, the second option you have outlined is probably the path of least resistance. :-) |
Thanks! |
Hi!
I'd like to add an
outputtypehandler
forDB_TYPE_NUMBER
that returns anint
if the corresponding data allows it or adecimal.Decimal
otherwise.So far I have two implementation variants but I'd appreciate your advise, maybe there is a better or more efficient way to do it...
V1: convert to
decimal.Decimal
and try to go back toint
:V2: handle as
str
and then either convert toint
ordecimal.Decimal
Are those methods reasonable ways to solve the problem or would you recommend a better solution?
The text was updated successfully, but these errors were encountered: