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

sql: bugfix to fractional year interval parsing #55230

Merged
merged 1 commit into from
Oct 6, 2020

Conversation

jordanlewis
Copy link
Member

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.

@jordanlewis jordanlewis requested review from otan and a team October 6, 2020 00:13
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@@ -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`, ``},
Copy link
Contributor

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?

Copy link
Member Author

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.
@jordanlewis
Copy link
Member Author

TFTR!

bors r+

@craig
Copy link
Contributor

craig bot commented Oct 6, 2020

Build succeeded:

@craig craig bot merged commit 1a973d2 into cockroachdb:master Oct 6, 2020
@rafiss
Copy link
Collaborator

rafiss commented Oct 7, 2020

does this need a backport? either before or after 20.2.0?

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

Successfully merging this pull request may close these issues.

sql: fractional years in intervals should be truncated at months
4 participants