You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In an older version of go-pg, it was possible to do:
result := []int32{}
_, err := db.Query(&result, "SELECT intfield FROM mytable")
At some time this very intuitive syntax was disallowed and regressed into using pg.Scan() and others, so I converted it to:
result := []int32{}
_, err := db.Query(pg.Scan(&result), "SELECT intfield FROM mytable")
But that resulted in this error:
json: cannot unmarshal number into Go value of type []int32
I'm puzzled where does the "json" part of the message comes from? The goal is to get a column of integers into a []int32 slice.
Edit:
I'm overthinking it: reverting the code back to db.Query(&result, "SELECT...") apparently works. Is there some documentation which explains when pg.Scan() is needed and when it isn't?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
In an older version of go-pg, it was possible to do:
At some time this very intuitive syntax was disallowed and regressed into using pg.Scan() and others, so I converted it to:
But that resulted in this error:
I'm puzzled where does the "json" part of the message comes from? The goal is to get a column of integers into a []int32 slice.
Edit:
I'm overthinking it: reverting the code back to
db.Query(&result, "SELECT...")
apparently works. Is there some documentation which explains whenpg.Scan()
is needed and when it isn't?Beta Was this translation helpful? Give feedback.
All reactions