GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(mysql): encode copyfrom enum values as strings by fzlzjerry · Pull Request #4613 · sqlc-dev/sqlc

Conversation

@fzlzjerry

@fzlzjerry fzlzjerry commented Sep 8, 2026

Copy link
Copy Markdown

Fixes #4324.

Generated non-null enums are defined string types. Passing them to mysqltsv.Encoder.AppendValue fails at runtime because they are neither a built-in string nor a driver.Valuer. The generated code compiles, but LOAD DATA cannot consume its rows.

Recognize the generated Go enum names, including the qualifier used for split models, and emit AppendString(string(value)). Nullable enum wrappers already implement driver.Valuer, so they keep the generic path. Type overrides are checked by their resolved Go type, not merely their SQL column type.

The production change is 11 added lines. The remaining files are CLI inputs and generated goldens for default arguments, parameter-struct pointers and split models. They cover multi-column and scalar enums, nullable values, an overridden enum, ordinary strings and INSERT/REPLACE conversion. Existing goldens, models, dependencies and public APIs are unchanged.

Validation:

  • The final CLI golden fails on the clean base and passes in both base and managed-db contexts, also with -race.
  • Real MySQL 9.7.2: the original generated code fails nine enum cases and passes twelve controls. All 21 cases pass after the fix, including exact stored values/counts and zero SHOW WARNINGS. Checked with -race on Go 1.26.8 and 1.27.0.
  • Full tagged suite with the CI's Go 1.26.5, CGO_ENABLED=0, live PostgreSQL 16.14/MySQL 9.7.2 and all required process plugins: 6,889 passing test observations, zero failures. The 153 declared skips are unsupported replay contexts and one statement with no faithful rendering; none are missing tools.
  • Full generated-code corpus builds. All six CI build targets (Linux/macOS/Windows, amd64/arm64) build with CGO disabled. Native build and vet pass on Go 1.26.8 and 1.27.0; generator race tests and formatting pass.
  • govulncheck passes on Go 1.26.8. An additional scan on the older build/test compiler, Go 1.26.5, reports five standard-library advisories that also reproduce on the clean base. No toolchain/dependency changes are included.

REPLACE duplicate-key behavior stays with #4559. The runtime REPLACE cases use fresh keys to isolate the enum encoding problem; this PR does not claim to fix that separate semantic issue.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

maglicheev-check24 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@fzlzjerry
fix(mysql): encode copyfrom enum values as strings
44d7340
Generated non-null enums are named string types, which mysqltsv does not accept through AppendValue. Recognize generated enum names, including external model qualification, and emit AppendString with an explicit string conversion.

Keep nullable driver.Valuer wrappers, overrides and ordinary types on their existing paths. Add CLI golden cases for scalar arguments, parameter-struct pointers and split models, with nullable, overridden and text controls.

Verified the tagged CI suite with all required process plugins, six CGO-free build targets, and live MySQL round trips. REPLACE duplicate-key semantics remain separate from this encoding fix.

Fixes sqlc-dev#4324
Copilot AI lite review requested due to automatic review settings September 8, 2026 23:17
Copilot AI reviewed Sep 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@maglicheev-check24

maglicheev-check24 commented Sep 9, 2026

Copy link
Copy Markdown

@fzlzjerry Can confirm that the fix indeed works for my issue, the generated function is the same as the workaround I've developed in my code as a temporary fix

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@fzlzjerry

fzlzjerry commented Sep 13, 2026

Copy link
Copy Markdown
Author

Thanks for confirming this against your affected query, @maglicheev-check24. Good to know the generated function matches your working workaround.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Jille

Jille commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

(I'm the original :copyfrom contributor and owner of mysqltsv.)

I had a quick peek at the code and I'm pondering which route is the best:

  1. The approach taken in this PR
  2. mysqltsv could use reflection to cast all string types to string.
  3. We could make all enums implement driver.Valuer which makes mysqltsv and other libraries handle this automatically.

The most common mysql driver seems to use approach 2:
https://github.com/go-sql-driver/mysql/blob/4b12a5b6e7fb8951a847f1b61485a59f337ada18/statement.go#L208

So that's probably the approach we should also take?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

MySQL copyfrom throws "can't encode type models.ExperienceLocationsType to TSV" if models.ExperienceLocationsType is a string enum

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@fzlzjerry @maglicheev-check24 @Jille
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.