-
Notifications
You must be signed in to change notification settings - Fork 44
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return INTERVAL from duration_in(TEXT, StateAgg). #378
Conversation
2c995f7
to
b82c73f
Compare
b82c73f
to
8c9eb4b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Timestamps are a bit weird, and this does return different results from what postgres does for some calculations. I think this is actually fine, but I do want to think on this a little more.
extension/src/state_aggregate.rs
Outdated
@@ -279,11 +292,13 @@ mod tests { | |||
None, | |||
); | |||
assert_eq!( | |||
31536120000000, | |||
"8760:02:00", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presumably we wouldn't want to call out to postgres for every timestamptz calculation, but it is worth considering that this a bit different from the postgres result:
postgres=# select ('2020-12-31 00:02:00+00'::timestamptz - '2020-01-01 00:00:00+00'::timestamptz)::interval;
interval
-------------------
365 days 00:02:00
(1 row)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that's interesting! So it's the responsibility of the caller to do the math and fill out all fields of Interval?! What a pain. I'll look into it. Maybe I'm just holding it wrong.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It took me a while to figure out how and where postgresql is doing this, but I did find it, and I've documented it here, and I'm calling the same function.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
bors r+ |
Build succeeded: |
No description provided.