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

Fetching bytea into []byte throws parse error #212

Closed
roobre opened this issue Jul 29, 2017 · 1 comment
Closed

Fetching bytea into []byte throws parse error #212

roobre opened this issue Jul 29, 2017 · 1 comment

Comments

@roobre
Copy link
Contributor

roobre commented Jul 29, 2017

Kallax seems to throw an error when fetching a model with a field of type []byte, tagged as sqltype:"bytea":

type Awesome struct {
        kallax.Model `table:"awesome"`
        Data []byte  `sqltype:"bytea"`
}

2017/07/28 18:46:45 2 : sql: Scan error on column index 7: kallax: unable to parse array; expected '{' at offset 0

It seems like it's trying to decode the field somehow, instead of blindly copy the byte array.

I'm not sure if this is the correct way of modelling binary blobs. If it's not, some hints on how to do it properly would be appreciated.

@erizocosmico
Copy link
Contributor

Thanks for reporting this!

Yes, all slices and arrays try to scan a postgres array type. That said, kallax should be smart enough to not do that in the case of []byte. In fact, I don't think it makes sense to have a []byte that's not a bytea, since it's being treated right now as a smallint[].

We'll probably special-case []byte to always be bytea and avoid the array scanning.

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

No branches or pull requests

2 participants