A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/oracle/python-oracledb/issues/510 below:

Fetch DF picks wrong datatype when expression is present · Issue #510 · oracle/python-oracledb · GitHub

  1. What versions are you using?
    3.2

  2. Is it an error or a hang or a crash?
    Just incorrect value (number is truncated as consequence of wrong data type)

  3. What error(s) or behavior you are seeing?
    Doubles are being casted as int, losing decimal part

  4. Does your application call init_oracle_client()?
    No but wrong value occurs regardless

  5. Include a runnable Python script that shows the problem.

import oracledb
import pyarrow as pa

# oracledb.init_oracle_client()

conn = oracledb.connect("...")
with conn.cursor() as cursor:
    try:
        cursor.execute("drop table t_random")
    except:
        pass

    cursor.execute("create table t_random as select 1 n1 from dual")

print("Plain select from table")
odf = conn.fetch_df_all("select n1 from t_random")
print(odf.column_arrays())
print(pa.Table.from_arrays(arrays=odf.column_arrays(), names=odf.column_names()))


print("\nDivided by a decimal, OracleArrowArray is int64 (wrong)")
odf = conn.fetch_df_all("select n1/sqrt(252) n from t_random")
print(odf.column_arrays())
print(pa.Table.from_arrays(arrays=odf.column_arrays(), names=odf.column_names()))


print("\nForce casting to double")
odf = conn.fetch_df_all("select TO_BINARY_DOUBLE(n1/sqrt(252)) n from t_random")
print(odf.column_arrays())
print(pa.Table.from_arrays(arrays=odf.column_arrays(), names=odf.column_names()))


print("\nPlain old DB API")
with conn.cursor() as cursor:
    cursor.execute("select n1/sqrt(252) n from t_random")
    print(cursor.fetchone())

And output looks like

Plain select from table
[OracleArrowArray(name=N1, len=1, type=double)]
pyarrow.Table
N1: double
----
N1: [[1]]

Divided by a decimal, OracleArrowArray is int64 (wrong)
[OracleArrowArray(name=N, len=1, type=int64)] <------ THIS IS INCORRECT, SHOULD BE DOUBLE
pyarrow.Table
N: int64
----
N: [[0]]

Force casting to double
[OracleArrowArray(name=N, len=1, type=double)]
pyarrow.Table
N: double
----
N: [[0.06299407883487121]]

Plain old DB API
(0.06299407883487121,)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4