Closed AubSs closed 2 years ago
Hi. Thanks for opening this issue.
Currently, it's not possible to scan single-column rows into pgtype like that (as you would do it with string
or int
). The problem happens because pgtype.UUID
is actually a struct and scany treats that case as scanning into a struct.
The workaround for your situation would be the following:
-- sql : SELECT uuid FROM ...
type Row struct {
ID pgtype.UUID
}
var rows []Row
if err := pgxscan.Select(ctx, pg.Client(tx), &rows, sql, args...); err != nil {
return nil, err
}
var ids []pgtype.UUID
// extract ids from rows
I will think about some kind of exceptions for scany to support that case without workarounds.
Ok, thx !
@AubSs Hi! I just released a new version of scany that now includes this feature.
@georgysavva Hello! I just use the new functionality, and it's perfectly working! Many thanks to you!
How to scan one column (and one or multiple rows) into pgx type ?
I'm getting errors like
scany: scan row into struct fields: can't scan into dest[0]: cannot assign &{[some bytes ...] 2} into *[]pgtype.UUID
all my attempts ended in failures ..