Re: [cx-oracle-users] More than one type returned for a single column
Brought to you by:
atuining
From: Anssi K. <aka...@gm...> - 2012-09-30 00:42:38
|
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 > > |