-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
sql: bugfix to fractional year interval parsing #55230
Conversation
@@ -374,8 +374,9 @@ func TestPGIntervalSyntax(t *testing.T) { | |||
{`1yr`, types.IntervalTypeMetadata{}, `1 year`, ``}, | |||
{`1yrs`, types.IntervalTypeMetadata{}, `1 year`, ``}, | |||
{`1.5y`, types.IntervalTypeMetadata{}, `1 year 6 mons`, ``}, | |||
{`1.1y`, types.IntervalTypeMetadata{}, `1 year 1 mon 6 days`, ``}, | |||
{`1.11y`, types.IntervalTypeMetadata{}, `1 year 1 mon 9 days 14:24:00`, ``}, | |||
{`1.1y`, types.IntervalTypeMetadata{}, `1 year 1 mon`, ``}, |
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.
math.Mod
can get tricky -- can you add tests for -1.1y
?
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.
Added negative versions of all of these test cases and verified that it's the same in Postgres.
Previously, parsing an interval with a fractional year would produce an interval that was "too precise" compared to Postgres, which we aim to be compatible with. Postgres truncates the precision of fractional years in intervals to months; we did not. This commit fixes the issue. For example, '1.1 year'::interval will become '1 year 1 month' instead of a quantity with days and hours. Release note (sql change): parsing intervals with fractional years now produces intervals with no more precision than months, to match the behavior of Postgres.
018beb0
to
6100650
Compare
TFTR! bors r+ |
Build succeeded: |
does this need a backport? either before or after 20.2.0? |
Previously, parsing an interval with a fractional year would produce an
interval that was "too precise" compared to Postgres, which we aim to be
compatible with. Postgres truncates the precision of fractional years in
intervals to months; we did not.
This commit fixes the issue. For example, '1.1 year'::interval will
become '1 year 1 month' instead of a quantity with days and hours.
Closes #55226.
Release note (sql change): parsing intervals with fractional years now
produces intervals with no more precision than months, to match the
behavior of Postgres.