-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Any way to support JSON values inserted using []byte rather than string #819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is limitation of MySQL text protocol. How about stop using |
BTW, can hex decimal literal be used for JSON? |
@methane I could stop using |
I think best solution is using string type. |
@methane One question, how much performance is gained or not with |
OK, nvm, seems we aren't using XAPI, so forced into 2-RTT by the protocol. |
Think this fudge works...
|
I don't know about SQLBoiler and I don't want to pay my time to learn it only for this issue. Additionally, you can skip 2-RTT by reusing explicitly prepared statement. |
json encoded data is represented as bytes however it should be interpolated as a string. Signed-off-by: Alex Snast <[email protected]>
json encoded data is represented as bytes however it should be interpolated as a string. Signed-off-by: Alex Snast <[email protected]>
json encoded data is represented as bytes however it should be interpolated as a string Fixes go-sql-driver#819
json encoded data is represented as bytes however it should be interpolated as a string Fixes go-sql-driver#819
You can't interpolate a []byte into a JSON field: go-sql-driver/mysql#819
You can't interpolate a []byte into a JSON field: go-sql-driver/mysql#819
You can't interpolate a []byte into a JSON field: go-sql-driver/mysql#819
You can't interpolate a []byte into a JSON field: go-sql-driver/mysql#819
You can't interpolate a []byte into a JSON field: go-sql-driver/mysql#819
You can't interpolate a []byte into a JSON field: go-sql-driver/mysql#819
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
andinterpolateParams=true
then it will fail with: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 disablinginterpolateParams
, 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 fromstring
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
orstring
, 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
The text was updated successfully, but these errors were encountered: