Skip to content

fix(golang): cast string-enum fields in MySQL copyfrom encoder#4428

Open
SAY-5 wants to merge 1 commit intosqlc-dev:mainfrom
SAY-5:fix/copyfrom-mysql-enum
Open

fix(golang): cast string-enum fields in MySQL copyfrom encoder#4428
SAY-5 wants to merge 1 commit intosqlc-dev:mainfrom
SAY-5:fix/copyfrom-mysql-enum

Conversation

@SAY-5
Copy link
Copy Markdown
Contributor

@SAY-5 SAY-5 commented May 5, 2026

Fixes #4324.

mysqltsv.AppendValue uses a strict type-switch and rejects string-derived enum types (e.g. type ExperienceLocationsType string) with can't encode type X to TSV. The MySQL copyfrom template now detects fields whose Type matches a generated enum (bare or models.-qualified) and emits e.AppendString(string(row.Field)) instead of e.AppendValue(row.Field).

A regression test under internal/endtoend/testdata/copyfrom_mysql_enum/mysql/ mirrors the reporter's schema and query; it fails on main and passes with this change. All other replay tests still pass.

mysqltsv.AppendValue uses a strict type-switch and rejects
string-derived enum types (e.g. ExperienceLocationsType) with
"can't encode type X to TSV". Detect string enums in the
go-sql-driver-mysql copyfrom template and emit
AppendString(string(field)) instead.

Fixes sqlc-dev#4324

Signed-off-by: SAY-5 <saiasish.cnp@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

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

1 participant