fix: set Type field on INSERT parameter columns for correct schema resolution#4299
Open
rayakame wants to merge 8 commits intosqlc-dev:mainfrom
Open
fix: set Type field on INSERT parameter columns for correct schema resolution#4299rayakame wants to merge 8 commits intosqlc-dev:mainfrom
rayakame wants to merge 8 commits intosqlc-dev:mainfrom
Conversation
This reverts commit d710427.
Contributor
Author
|
As far as I can see the failing test is only something that went wrong with docker |
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.
I'm writing an external sqlc plugin (sqlc-gen-better-python) and ran into a bug where
:copyfromqueries targeting tables in custom schemas send incorrect type information to plugins.When using a schema like this:
And a query like:
The plugin receives the parameter type as
name: "custom.mood"instead ofschema: "custom", name: "mood". This meant my plugin couldn't resolve the enum type to its definition in the catalog, since the schema was baked into the name string rather than being properly separated.I noticed that
:manySELECT queries on the exact same table returned correct type info, so the bug had to be specific to how INSERT parameter columns are built.Cause
The
*ast.ResTargetcase inresolveCatalogRefs(internal/compiler/resolve.go) buildsColumnstructs withDataType(a string like"custom.mood") but doesn't set the structuredTypefield (*ast.TypeNamewith separateSchemaandName). The shim ininternal/cmd/shim.gochecksTypefirst and falls back to puttingDataTypeintoNamewith an empty schema whenTypeis nil.Previous fix / possible unnecessary code
In
/internal/codegen/golang/postgresql_type.gothere is the functionfunc parseIdentifierString(name string) (*plugin.Identifier, error)which previously parsed the string generated bysdk.DataTypeinto a new*plugin.Identifier. As far as I've tested this, this function can just be removed now and thecolumn.Typecan be used directly.I could of course implement the same workaround in my own plugin, but I think fixing this at the source is the right approach.