On Wed, Aug 29, 2012 at 10:34 AM, Jacob Kaplan-Moss <ja...@jacobian.org> wrote: > Hey Shai -- > > Generally sounds like a good idea, I don't see why this shouldn't go > in. You might want to wait until someone with more Oracle experience > chimes in, but I'm having a hard time seeing why a number -> str -> > number dance would be a good idea.
The reason for it is because cx_Oracle doesn't create Decimal objects when fetching from the database. It only creates ints and floats. As a result, if you try to use a DecimalField(38), you're not going to be able to effectively store a 38-digit decimal number, even though Oracle supports that. You basically end up being limited to the precision of a float with some rounding error, since the value gets converted from NUMBER to float to Decimal. Using strings as the intermediate instead of floats allows the full precision to be used. In theory we could do this only for DecimalFields and leave the other numeric field types alone, by wrapping each individual DecimalField expression in the select list in a TO_CHAR() call. In practice this work has never been done because of the mess it would make of query generation, so we instead use a cx_Oracle API feature to transmit all numbers as strings and then sort it out later. There's another option that also hasn't been implemented, because it would mean dropping support for cx_Oracle versions older than 5.0.1. Perhaps the time has come to do that (I note that the oldest binary still listed at the cx_Oracle website is 5.1). This would involve removing the _rowhandler function and the numbers_as_strings setting and replacing it with an _outputtypehandler that would only be called once per column instead of on every single returned value. I've written a POC patch for this and so far, performance seems to be much improved, on par with using cx_Oracle without Django. https://github.com/ikelly/django/commit/086f502a1c2acb9db27531f7df78cb9df9ab83bd Shai, if you would be willing to try this patch, I'd like to hear your results. Please bear in mind that this is currently only a POC, so it could be buggy -- I've only run it through the basic tests. Cheers, Ian -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.