Re: [cx-oracle-users] More than one type returned for a single column
Brought to you by:
atuining
From: Jani T. <re...@gm...> - 2012-09-30 15:05:03
|
Oracle does have three different numeric datatypes: NUMBER and BINARY_FLOAT and BINARY_DOUBLE. NUMBER is most commonly used one and while defining column you can define percision, scale if needed. But it doesn't exatly tell is number integer or not. By setting scale to 0 (or not defining at all) you can only store integer numbers to a column. By looking source code of cx_Oracle it does make decision is output variable int, float or string based on NUMBER type returned (scale, precision taken into account) so I think it's purely possible to have to different output types - specially if you use code that creates columns on the fly. Like that sample query from dual. On Sun, Sep 30, 2012 at 3:42 AM, Anssi Kääriäinen <aka...@gm...>wrote: > > On Sun, Sep 30, 2012 at 3:12 AM, Chris Gould <chr...@to...>wrote: > >> Arent they really both type NUMBER ? >> >> > It have an (incorrect?) expectation that one column should have one result > type in Python. While float and int are close to each other in Python, they > do have differences, for example the '/' operator. > > The situation came up in trying to use outputtypefactory in Django, then > optimizing the case where the type of the result is guessed, see > https://github.com/shaib/django/blob/d10eaf28c864816e9bb8b0d1467e90b79291792a/django/db/backends/oracle/base.py#L772- the problem there is that half of the numbers are guessed as Decimal, > half as int. This isn't a nice situation, the APIs for Decimal and int are > very different. > > I don't know Oracle too well - is the situation such that the result is > NUMBER in Oracle, and there is no more information about the column > available from the DB? > > - Anssi > > > >> >> On Sunday, September 30, 2012, Anssi Kääriäinen wrote: >> >>> It seems it is possible to have more than one type returned for a single >>> column. Observe this test case: >>> >>> import cx_Oracle >>> print cx_Oracle.version >>> connection = cx_Oracle.connect('user/ >>> passwd@' + cx_Oracle.makedsn('localhost', 1521, 'xe')) >>> cur = connection.cursor() >>> cur.execute("select case when dbms_random.random > 0.5 then 0.1 else 0 >>> end from testtable") >>> vals = [] >>> vals.extend(row[0] for row in cur.fetchall()) >>> print set([type(v) for v in vals]) >>> >>> The output is: >>> 5.1.2 >>> set([<type 'float'>, <type 'int'>]) >>> >>> To me this seems surprising - shouldn't a column have the same type >>> across all rows in a single resultset? >>> >>> - Anssi >>> >> >> >> -- >> Sent from Gmail Mobile >> >> >> ------------------------------------------------------------------------------ >> Everyone hates slow websites. So do we. >> Make your web apps faster with AppDynamics >> Download AppDynamics Lite for free today: >> http://ad.doubleclick.net/clk;258768047;13503038;j? >> http://info.appdynamics.com/FreeJavaPerformanceDownload.html >> _______________________________________________ >> cx-oracle-users mailing list >> cx-...@li... >> https://lists.sourceforge.net/lists/listinfo/cx-oracle-users >> >> > > > ------------------------------------------------------------------------------ > Everyone hates slow websites. So do we. > Make your web apps faster with AppDynamics > Download AppDynamics Lite for free today: > http://ad.doubleclick.net/clk;258768047;13503038;j? > http://info.appdynamics.com/FreeJavaPerformanceDownload.html > _______________________________________________ > cx-oracle-users mailing list > cx-...@li... > https://lists.sourceforge.net/lists/listinfo/cx-oracle-users > > -- Jani Tiainen - Well planned is half done, and a half done has been sufficient before... |