Skip to content
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

error on jsonb field with binary_parameters #528

Open
rothskeller opened this issue Oct 31, 2016 · 4 comments
Open

error on jsonb field with binary_parameters #528

rothskeller opened this issue Oct 31, 2016 · 4 comments

Comments

@rothskeller
Copy link

I have binary_parameters=yes in my connection string so that I can efficiently set the values of some multimegabyte bytea columns.

Elsewhere in my database, I have jsonb columns. These work fine when binary_parameters is not set, but when it is set, I get "pq: unsupported jsonb version number 123" when updating a record containing a jsonb column.

It seems like I need binary_parameters off when working with jsonb, and on when working with huge bytea. And it's connection string parameter, so I can't have it both ways. Help?

@cbandy
Copy link
Contributor

cbandy commented Oct 31, 2016

The binary format for jsonb is prefixed with an 8-bit version. The current version is 1 followed by the plain/text JSON. (See jsonb_recv)

You could cast your []byte or json.RawMessage to string, signaling that it should be identified as text format. Or you could wrap/cast these to a sql.Scanner driver.Valuer that adds the version prefix. (I suspect both incur a copy of the memory...)

Since everything passes through database/sql before arriving at lib/pq, options are limited.

@cbandy
Copy link
Contributor

cbandy commented Jan 13, 2017

@rothskeller did you find a solution?

@rothskeller
Copy link
Author

Your suggestion of casting to string solved my problem, thanks. My apologies if you were waiting on a response from me.

Taik added a commit to Taik/sqlx that referenced this issue Apr 20, 2017
In order to support `binary_parameters` flag in lib/pq, we need to
explicitly return string type to signal lib/pq to send the field via
text format (lib/pq#528).
Taik added a commit to Taik/sqlx that referenced this issue Apr 20, 2017
In order to support `binary_parameters` flag in lib/pq, we need to
explicitly return string type to signal lib/pq to send the field via
text format (lib/pq#528).
@ivanovaleksey
Copy link

I guess this one could be close :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants