#4324·sqlc

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

Author: maglicheev-check24Created Mar 5, 2026Updated Sep 8, 2026
Labelsbug:books: mysql:wrench: golang:computer: darwin

Version

1.30.0

What happened?

When trying to run a query with LOAD DATA LOCAL INFILE, mySQL throws an error "can't encode type models.ExperienceLocationsType to TSV". Said models.ExperienceLocationsType is defined as:

type ExperienceLocationsType string

const (
	ExperienceLocationsTypeStartPoint      ExperienceLocationsType = "start_point"
	ExperienceLocationsTypePickupPoint     ExperienceLocationsType = "pickup_point"
	ExperienceLocationsTypeRedemptionPoint ExperienceLocationsType = "redemption_point"
	ExperienceLocationsTypeEndPoint        ExperienceLocationsType = "end_point"
)

but encoded as e.AppendValue(row.Type) in corresponding convertRowsForUpsertExperienceLocationsFixed() function

Manually changing AppendValue() function above to AppendString() fixes the issue, so I guess this should be done always in case LOAD DATA INFILE has to insert a string enum value.

Relevant log output

bash
can't encode type models.ExperienceLocationsType to TSV

Database schema

sql
create table experience_locations
(
    location_id   varchar(512)                                                          not null,
    type          enum ('start_point', 'pickup_point', 'redemption_point', 'end_point') not null
)

SQL queries

sql
-- name: UpsertExperienceLocations :copyfrom
REPLACE INTO experience_locations (location_id, type)
VALUES (?, ?);

Configuration

yaml
version: "2"

sql:
  - engine: mysql
    schema: migrations
    queries: queries
    gen:
      go:
        package: models
        sql_package: "database/sql"
        sql_driver: "github.com/go-sql-driver/mysql"
        out: models

Playground URL

https://play.sqlc.dev/p/f8a7a9571876a2c4956bfed6b81df52da25073cc2975700512372529e8b5502b

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go