Repository navigation
compiler: apply column overrides to BETWEEN parameters - #4734
Open
farisbasha wants to merge 1 commit into
Open
farisbasha wants to merge 1 commit into
farisbasha wants to merge 1 commit into
Conversation
On the MySQL and SQLite engines, a parameter on either side of a BETWEEN was resolved without the name of the column it is compared to, so a column override (go_type or go_struct_tag) did not apply to it: the params got the default type while the same column compared with = got the override. Set OriginalName as the other column-reference paths do.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On the MySQL and SQLite engines, a column override does not apply to the parameters of a
BETWEEN. The same column compared with=gets the override, so one query takes the custom type while its neighbour takes the plain one:Named params (
BETWEEN sqlc.arg(min_code) AND sqlc.arg(max_code)) behave the same way, and so doesgo_struct_tag. The PostgreSQL engine and the core analyzer (SQLCEXPERIMENT=coreanalyzer) already apply the override here.Cause: in
resolveCatalogRefs, the*ast.BetweenExprbranch builds the parameter column withoutOriginalName. The override lookup in codegen matches onOriginalNamewhen it is set and onNameotherwise. For these paramsNameisfrom_code/to_codeor thesqlc.argname, so it never matchescode. TheA_Exprcolumn-reference branch setsOriginalName: c.Name.Fix: set
OriginalName: c.Namein theBETWEENbranch as well. The param names stay the same.Test: new end-to-end case
internal/endtoend/testdata/overrides_betweenfor mysql and sqlite, covering positional and named params plus an=query for comparison. Without the fix,TestReplay/base/overrides_between/{mysql,sqlite}fails on theFromCode/ToCode/MinCode/MaxCodefield types. With the fix it passes.Tests were run on a Linux server:
go test ./...: everyTestReplaycase passes, including the new one. The only failures areTestValidSchemaandinternal/x/expander, which need a live PostgreSQL/MySQL ("not installed"); they fail the same way onmainandgo vet ./internal/compiler/. No MySQL or PostgreSQL server was running there, so the database-backed contexts and tests skipped.This PR was prepared with AI assistance (Claude).