Description
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