Re: [cx-oracle-users] More than one type returned for a single column
Brought to you by:
atuining
From: Anthony T. <ant...@gm...> - 2012-09-30 22:16:30
|
On Sun, Sep 30, 2012 at 12:43 PM, Anssi Kääriäinen <aka...@gm...> wrote: > On Sun, Sep 30, 2012 at 8:11 PM, Jani Tiainen <re...@gm...> wrote: >> >> That is exactly correct. You didn't provided initial precision nor scale >> so it's adapting to whatever data is stored there. >> >> So when you save data Oracle stores data "as is". But I did some code >> diving [1] to cx_oracle and it seems to do some analysis to returned data >> and figures out return type. >> > > Yes, it is adapting to the data. The problem I have is that my expectation > is that each SQL column has a single type. This is not reflected in the > Python return types. > > Maybe my expectation isn't valid... DBAPI2 doesn't seem to require single > type for single column, the only requirement I see is that > cursor.description tells the type of the column, and one type available is > NUMBER. How NUMBER is then represented in Python is left unspecified. > > - Anssi Which type is returned is dependent on the precision and/or scale as defined by the column being returned. If the number of digits after the decimal point is 0 then an integer is returned; otherwise, a float is returned. You can completely bypass this algorithm and do your own thing by using an outputtypehandler method. See the documentation for the details of what this method expects to receive and what is expected to be returned. If you need further help, though, let me know and I can provide an example. The ReturnUnicode example should be a good start, though. Anthony |