go-pg / pg

Golang ORM with focus on PostgreSQL features and performance
https://pg.uptrace.dev/
BSD 2-Clause "Simplified" License
5.67k stars 404 forks source link

fix buff size comparison & proper error message #1951

Open tufanbarisyildirim opened 2 years ago

tufanbarisyildirim commented 2 years ago

When scanning a byte column ReadBytes expect to have exact size of a []byte We should be able to read bytes into a buffer that is bigger than our data size in this column. This cause errors when you have a fixed field size in code but variable size in database. The error message was also misleading like it was checking if we have enough space but it actually expect to have exact size. So, changed the comparison to accept bigger buffers and to properly print the source & destination buffer size.

elliotcourant commented 2 years ago

Is there a way that this behavior could be proven with a unit test, even if that test is just for the ReadBytes function itself?