Replies: 1 comment 1 reply
|
You can use
AFAIK, specifying the columns instead of * is a good practice for precisely this reason - it is more tolerant of DB changes (also it can have better performance by only selecting what is needed). |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I'm using
pgx.RowToStructByNamewith "db" struct tag to avoid scanning manually. My problem is, for example, when the table has 4 fields but the struct only has 3 fields, an error is returned like "struct doesn't have corresponding row field ...".Like in the situation that we applied migration but the code was not synced yet. This problem leads to a decision: I must ensure the db schema and the struct must matched together at runtime, either I must specify explicitly columns insead of using
*in the SELECT statement. Can the function somehow just ignore that column and scan result into existing struct fields?All reactions