Skip to content

Any way to support JSON values inserted using []byte rather than string #819

Closed
@dterei

Description

@dterei

Issue description

Golang uses []byte as the underlying type for JSON values. However, if you try to insert a value into MySQL for a JSON column using []byte and interpolateParams=true then it will fail with:

unable to upsert for t: Error 3144: Cannot create a
JSON value from a string with CHARACTER SET 'binary'

This appears to be becuase MySQL doesn't support inserting binary values into JSON columns, it wants an explicit character set to be specified (see bug).

While using string is a workaround of sorts, or disabling interpolateParams, hoping you may have better advice on how to solve this?

This problem causes issues when using ORM libraries like SQLBoiler that map a JSON field in a struct to []byte before invoking the SQL interface (see bug raised with SQLBoiler). SQLBoiler folks don't want to change their mapping from string to []byte for JSON just for MySQL.

Arguably the Go SQL interface should support JSON as a valid type rather than forcing it to be mapped to []byte or string, then go-sql-driver can decide on the mapping itself.

Configuration

Driver version (or git SHA): v1.4.0

Go version: 1.10.1

Server version: MySQL 5.7.21

Server OS: Arch Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions