Skip to content

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

@maglicheev-check24

Description

@maglicheev-check24

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

can't encode type models.ExperienceLocationsType to TSV

Database schema

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

SQL queries

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

Configuration

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions