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

Interval literals with year/months have different number of seconds w.r.t. Python #570

Open
dvarrazzo opened this issue Jun 16, 2017 · 2 comments
Milestone

Comments

@dvarrazzo
Copy link
Member

select '-1 year -2 mons +3 days -04:05:06'::interval doesn't return the correct value in Python

@dvarrazzo dvarrazzo added this to the psycopg 2.7.2 milestone Jun 16, 2017
@dvarrazzo
Copy link
Member Author

Not a bug in the sign as I imagined: postgres adds 6 hours every year or every 12 months (but not 3 hours for 6 months or something like that).

I think it makes more sense to apply the same conversion, so that extract(epoch from interval) matches the timedelta.total_seconds() of the returned object.

Also note that these intervals are pretty specific: they are not obtained by the difference between timestamps, which is always expressed in months. Also, there is no problem of roundtrips because with Python intervals you can't express months and years.

dvarrazzo added a commit that referenced this issue Jun 16, 2017
This is the same operation performed by postgres when extracting the
number of seconds of an interval:

    =# select extract(epoch from '1 year'::interval) / 60 / 60 / 24;
     ?column?
    ----------
       365.25

This way `extract(epoch from interval)` will match the resulting
`timedelta.total_seconds()`.

Close #570
dvarrazzo added a commit that referenced this issue Jun 16, 2017
This is the same operation performed by postgres when extracting the
number of seconds of an interval:

    =# select extract(epoch from '1 year'::interval) / 60 / 60 / 24;
     ?column?
    ----------
       365.25

This way `extract(epoch from interval)` will match the resulting
`timedelta.total_seconds()`.

Close #570
dvarrazzo added a commit that referenced this issue Jun 16, 2017
This is the same operation performed by postgres when extracting the
number of seconds of an interval:

    =# select extract(epoch from '1 year'::interval) / 60 / 60 / 24;
     ?column?
    ----------
       365.25

This way `extract(epoch from interval)` will match the resulting
`timedelta.total_seconds()`.

Close #570
@dvarrazzo dvarrazzo modified the milestones: psycopg3, psycopg 2.7.2 Jun 17, 2017
@dvarrazzo
Copy link
Member Author

Not closing now this ticket. This behaviour has been "broken" this way forever (I thought it was broken in the reimplementation for #536).

@dvarrazzo dvarrazzo changed the title Interval literals with mixed signs not parsed correctly Interval literals with year/months have different number of seconds w.r.t. Python Jun 17, 2017
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

1 participant