You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When selecting a column of type "timestamp with time zone" with value "infinity" or "-infinity" psycopg converts it to datetime type without timezone. For all other values psycopg converts to datetime type with timezone. Datetime with and without timezone are not comparable which leads to confusing errors:
importpsycopg2conn=psycopg2.connect("postgresql://...")
cur=conn.cursor()
cur.execute("""SELECT '2017-01-01 12:34:56'::timestamp with time zone""")
normal=cur.fetchall()[0][0]
printnormalcur.execute("""SELECT 'infinity'::timestamp with time zone""")
inf=cur.fetchall()[0][0]
printinfprintnormal>inf
2017-01-01 12:34:56+01:00
9999-12-31 23:59:59.999999
Traceback (most recent call last):
File "demo-timezone.py", line 25, in <module>
print normal > inf
TypeError: can't compare offset-naive and offset-aware datetimes
The text was updated successfully, but these errors were encountered:
When selecting a column of type "timestamp with time zone" with value "infinity" or "-infinity" psycopg converts it to datetime type without timezone. For all other values psycopg converts to datetime type with timezone. Datetime with and without timezone are not comparable which leads to confusing errors:
The text was updated successfully, but these errors were encountered: