oracle / python-oracledb

Python driver for Oracle Database conforming to the Python DB API 2.0 specification. This is the renamed, new major release of cx_Oracle
https://oracle.github.io/python-oracledb
Other
328 stars 66 forks source link

systimestamp different between cx_Oracle and oracledb #140

Closed BayerSe closed 1 year ago

BayerSe commented 1 year ago
  1. What versions are you using?
Oracle 19c
platform.platform: Linux-5.4.0-137-generic-x86_64-with-glibc2.31
sys.maxsize > 2**32: True
platform.python_version: 3.10.9
oracledb.__version__: 1.2.2
  1. Is it an error or a hang or a crash?

Error

  1. What error(s) or behavior you are seeing?

The value of systimestamp is wrong, it is different to the value in the database and the value reported by cx_Oracle.

  1. Does your application call init_oracle_client()?

No.

  1. Include a runnable Python script that shows the problem.
import oracledb
import cx_Oracle

user ="..."
password = "..."
dsn = "...

with oracledb.connect(user=user, password=password, dsn=dsn) as connection:
    with connection.cursor() as cursor:
        sql = """select systimestamp, current_timestamp from dual"""
        for r in cursor.execute(sql):
            print(r)

with cx_Oracle.connect(user=user, password=password, dsn=dsn) as connection:
    with connection.cursor() as cursor:
        sql = """select systimestamp, current_timestamp from dual"""
        for r in cursor.execute(sql):
            print(r)

    import oracledb
    print("oracledb.__version__:", oracledb.__version__)
(datetime.datetime(2023, 2, 10, 12, 0, 22, 342835), datetime.datetime(2023, 2, 10, 11, 0, 22, 342837))
(datetime.datetime(2023, 2, 10, 12, 0, 22, 648352), datetime.datetime(2023, 2, 10, 12, 0, 22, 648355))

The value of "systimestamp" is off by 1 hour when using oracledb instead of cx_Oracle.

The values reported by the database are:

2023-02-10 12:05:12.906225 +01:00
2023-02-10 11:05:12.906228 +00:00
cjbj commented 1 year ago

https://python-oracledb.readthedocs.io/en/latest/user_guide/globalization.html#thin-mode-locale-aware-number-and-date-conversions

BayerSe commented 1 year ago

Oh I see. Thanks!

anthony-tuininga commented 1 year ago

If you want them to be the same, make sure to set the session time zone. The default session time zone for thin mode is UTC whereas for thick mode it is the client's time zone. You can request an enhancement to thin mode to do the same.