You and Nagh suspected correctly: it's a Python thing, but it's just a display thing. You're not losing timestamp precision.
The cx_Oracle Python library converts Oracle date types (Date, Timestamp..) into one of Python's date types, datetime.
When a datetime
object is printed out as a string, (ie, its __str__()
method is called), it prints out in ISO 8601 format, using datetime.isoformat()
- this method is where the decision not to print milliseconds when they are 0 is made (actually, a datetime
has no millisecond field, it instead has microseconds, but same point).
However, this is just the string representation of the datetime
object. All of the time information is still there for you to use.
If you want to display milliseconds all the time you have to be explicit; try using strftime()
:
from datetime import datetime
now = datetime.now()
print now
# >>> 2013-11-28 15:34:47.223000
now = now.replace(microsecond=0) # Remove milliseconds
print now
# >>> 2013-11-28 15:34:47
print now.strftime('%Y-%m-%d %H:%M:%S.%f')
# >>> 2013-11-28 15:34:47.000000