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

[typing] Clean up NewDecimalWithPrecision #778

Merged
merged 3 commits into from
Jun 27, 2024
Merged

Conversation

nathan-artie
Copy link
Contributor

We don't need to duplicate the logic for handling invalid decimal precisions since we never read from Decimal.Precision().

@nathan-artie nathan-artie requested a review from Tang8330 June 27, 2024 21:03
@@ -4,6 +4,13 @@ import (
"fmt"
)

const (
DefaultScale int32 = 5
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved these constants too since they are only used for decimal details.

@nathan-artie nathan-artie marked this pull request as ready for review June 27, 2024 21:09

// This is typically not possible, but Postgres has a design flaw that allows you to do things like: NUMERIC(5, 6) which actually equates to NUMERIC(7, 6)
// We are setting precision to be scale + 1 to account for the leading zero for decimal numbers.
precision = scale + 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come we don't need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we have this exact logic in NewDetails() and we don't read from Decimal.Precision() except for tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. We should refactor the precision function then

func (d *Decimal) Precision() int32 {
	return NewDetails(d.precision, d.Scale()).Precision()
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just as soon as kill Precision, we don't need it.

@nathan-artie nathan-artie merged commit b7f5f96 into master Jun 27, 2024
1 check passed
@nathan-artie nathan-artie deleted the nv/clean-up-decimal branch June 27, 2024 21:37
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.

2 participants