From: Marcos P. <msa...@gr...> - 2003-08-28 14:12:19
|
I think that the right way is to have a decimal type, with the same features as the oracle number. We are using Tim Peters' fixedpoint module for that. http://fixedpoint.sourceforge.net/ El jue, 28-08-2003 a las 15:59, Anthony Tuininga escribi=F3: > Unfortunately, Oracle declares the "integer" to be without scale and > precision. Internally, cx_Oracle checks the scale and precision to > determine whether or not an integer ought to be returned. Specifically, > if the precision is between 1 and 9 and the scale is 0, an integer is > returned; otherwise, a float is returned. >=20 > This has always annoyed me but I don't know a good way around it. Oracle > has a numeric precision exceeding floating point by a great deal so a > while ago I added a "switch" OPT_NumbersAsStrings which, if set, will > return all numbers as strings instead of integers or floating point > numbers. This is useful for retaining the precision of the Oracle > numbers. You could use that, if you wish but it still requires you to > run int() on the result. >=20 > I have considered a method for telling cx_Oracle that the values ought > to be returned as integers, ignoring the precision and scale, but I > haven't come up with anything useful yet. Got any suggestions? One > possibility is the following: >=20 > vars =3D cursor.execute("select cast(1 as int) from dual") > vars[0].returntype =3D cx_Oracle.INTEGER > result, =3D cursor.fetchone() >=20 > Another is: >=20 > cursor.define(1, cx_Oracle.INTEGER) > cursor.execute("select cast(1 as int) from dual") > result, =3D cursor.fetchone() >=20 > At this point, result would be an integer. Neither is particularly > pleasant but perhaps better than the current situation. Any thoughts? >=20 > On Thu, 2003-08-28 at 04:05, Marcos S=E1nchez Provencio wrote: > > Why is it that I get 1.0 when I ask for=20 > >=20 > > select cast(1 as int) from dual > > ? > >=20 > > Is this Oracle?, Python?, me? --=20 gpg --recv-keys --keyserver wwwkeys.pgp.net B9AD9B1B |