Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

dolthub/dolt#7128 - String to number conversion #3136

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

Open
elianddb wants to merge 2 commits into main
base: main
Choose a base branch
Loading
from elianddb/7128-fix-string-double-truncation

Conversation

@elianddb
Copy link
Contributor

@elianddb elianddb commented Aug 1, 2025
edited
Loading

Fixes dolthub/dolt#7128
Previously, strings like "123.456abc" would throw errors instead of converting to 123.456 as in MySQL. This change adds MySQL-compatible truncation logic that extracts valid numeric prefixes while handling edge cases like whitespace, scientific notation, and pure non-numeric strings.

Copy link
Contributor

nicktobey commented Aug 3, 2025
edited
Loading

A thought: compatibility with MySQL is important, but I also think that throwing an error is probably better behavior (plus having more MySQL-specific behavior in the engine will make it harder to support other dialects like Postgres.)

So I would propose instead to make this behavior configurable, keep the current behavior as the default, and have GMS use the MySQL-specific behavior when a configuration flag is set.

elianddb reacted with thumbs up emoji elianddb reacted with eyes emoji

@elianddb elianddb force-pushed the elianddb/7128-fix-string-double-truncation branch from 60cefe8 to a8089e1 Compare August 4, 2025 16:36
@elianddb elianddb force-pushed the elianddb/7128-fix-string-double-truncation branch from a8089e1 to 9a292fc Compare August 4, 2025 20:15
Name: "mysql_string_to_number system variable",
Assertions: []ScriptTestAssertion{
{
Query: "SELECT @@mysql_string_to_number",
Copy link
Contributor

@nicktobey nicktobey Aug 4, 2025

Choose a reason for hiding this comment

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

Are these copied from another test? Do these different variables interact with each other?

I'm worried this is copy-pasting code and tests. If we have a lot of variables that all have global/session/local variables like this with specific rules, we should probably have a special test for those that doesn't duplicate code.

},
{
Query: "SELECT CAST('123abc' AS SIGNED)",
Expected: []sql.Row{{int64(0)}},
Copy link
Contributor

@nicktobey nicktobey Aug 4, 2025

Choose a reason for hiding this comment

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

The original behavior throws an error, right? This test seems to imply that it returns 0.


// Handle string-to-decimal conversion for mysql_string_to_number mode
if strVal, ok := val.(string); ok && sql.ValidateStringToNumberMode(ctx) {
if convertedVal, _, err := types.Float64.Convert(ctx, strVal); err == nil {
Copy link
Contributor

@nicktobey nicktobey Aug 5, 2025

Choose a reason for hiding this comment

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

So if the flag is set, we convert to a decimal by converting to a float first?

It's not clear from looking at this function why this produces the correct behavior.

Copy link
Contributor

Let's pick a more descriptive name for the variable.

Some possibilities:

  • @@truncate_char_cast_to_number (defaulting to false)
  • @@strict_char_cast_to_number (defaulting to true)

The others might have their own ideas, so maybe we should ask them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@nicktobey nicktobey nicktobey left review comments

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Truncate strings when converting to double

AltStyle によって変換されたページ (->オリジナル) /