Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"timestamp with time zone" and infinity value select #536

Closed
plocharz-9livesdata opened this issue Mar 21, 2017 · 1 comment
Closed

"timestamp with time zone" and infinity value select #536

plocharz-9livesdata opened this issue Mar 21, 2017 · 1 comment
Milestone

Comments

@plocharz-9livesdata
Copy link

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:

import psycopg2

conn = psycopg2.connect("postgresql://...")
cur = conn.cursor()
cur.execute("""SELECT '2017-01-01 12:34:56'::timestamp with time zone""")
normal = cur.fetchall()[0][0]
print normal

cur.execute("""SELECT 'infinity'::timestamp with time zone""")
inf = cur.fetchall()[0][0]
print inf

print normal > 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
@dvarrazzo dvarrazzo added this to the psycopg 2.7.2 milestone Mar 21, 2017
@dvarrazzo
Copy link
Member

It seems an error, yes. I'll look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants