'Fractional Precision Truncated when Setting Timestamp Column using Bind Variable

I have a table in Oracle SQL with a column "CURR_TS", which is of type TIMESTAMP (Uniform Type Code 180).

I am trying to set the value of CURR_TS using a Python SQL connection .execute() method. I pass a datetime.datetime.utcnow() object as a bind variable in the .execute() method. Relevant code snippets are below:

query_str = """
  update my_table
    set curr_ts = :curr_ts
  where
    (...rest of query string)
"""

bind_variables = {'curr_ts' : datetime.datetime.utcnow() }
SQL_Connection_Object(query_str).execute(connection_var, bind_variables=bind_variables, ...)

The query runs smoothly, the values get updated in the table, EXCEPT the fractional seconds are truncated and rounded to the nearest second. When I query the table, I see values in the CURR_TS column like "09-Mar-22 01:01:01.000000". Whereas the debug statements for the query clearly show a non-zero fractional second value:

--bindVariables:{'curr_ts': datetime.datetime(2022, 3, 9, 1, 1, 1, 441953)}

What should I be doing to get the fractional portions of the second to stick? Do I need to wrap the bind variable :curr_ts in some cast or conversion statement in the SQL query directly?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source