Movatterモバイル変換


[0]ホーム

URL:


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

Fix MySQL Mathematical Expression Type Inference#4172

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
rubensantoniorosa2704 wants to merge2 commits intosqlc-dev:main
base:main
Choose a base branch
Loading
fromrubensantoniorosa2704:feat/mysql-expression-type-inference

Conversation

@rubensantoniorosa2704
Copy link
Contributor

@rubensantoniorosa2704rubensantoniorosa2704 commentedNov 7, 2025
edited
Loading

This implements type inference for MySQL mathematical expressions. Before this change, queries with arithmetic operations would generateinterface{} types, which meant no compile-time type safety. Now the compiler properly infers types based on the operands and operators.

Before:

typeListTestRowstruct {A1Floatinterface{}`json:"a1_float"`// was interface{}}

After:

typeListTestRowstruct {A1Floatstring`json:"a1_float"`// now string (MySQL DECIMAL)}

What changed

  • AddedinferExprType() that recursively analyzes SQL expressions to determine their types
  • Handles column references, constants, binary operations, and type casts
  • MySQL-specific type rules: division returns decimal, float operations return float, nullability propagates correctly
  • Enhanced COALESCE to use type inference instead of always returninginterface{}
  • Added "div" and "mod" to the mathematical operators list (MySQL uses symbolic names instead of/ and%)

Notes

The implementation is MySQL-specific for now. PostgreSQL and SQLite returnnil fromcombineGenericTypes() to maintain current behavior. There's a TODO comment about refactoringIsMathematicalOperator() to be engine-specific.

Closes#4153

@rubensantoniorosa2704rubensantoniorosa2704force-pushed thefeat/mysql-expression-type-inference branch froma4b354e toef78ff2CompareNovember 7, 2025 01:49
@rubensantoniorosa2704rubensantoniorosa2704force-pushed thefeat/mysql-expression-type-inference branch fromef78ff2 to605cbc5CompareNovember 7, 2025 01:50
@hts0000
Copy link

Hello, may I ask when this PR will be merged?

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

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

How can i get correct type

2 participants

@rubensantoniorosa2704@hts0000

[8]ページ先頭

©2009-2025 Movatter.jp