-
-
Notifications
You must be signed in to change notification settings - Fork 207
Closed
Description
There seems to be some peculiarity with the way the result from calling the age function is being interpreted. The postgres documentation suggests that an interval is returned but it seems something unusual is happening in how this is getting parsed by psycopg.
Minimal steps for replicating are this:
connection = psycopg.connect(...)
cursor = connection.cursor()
# This returns datetime.timedelta(days=6) when it should be 6 months and 6 days
cursor.execute("SELECT age('2020-07-07 00:00:00'::timestamp, '2020-01-01 00:00:00'::timestamp);").fetchone()[0]
# Whereas just subtracting the timestamps results in the right output: datetime.timedelta(days=188)
cursor.execute("SELECT '2020-07-07 00:00:00'::timestamp - '2020-01-01 00:00:00'::timestamp;").fetchone()[0]Metadata
Metadata
Assignees
Labels
No labels