Closed dclipca closed 3 years ago
Hello!
scany just passes your field to the pgx library, it does by taking a reference: &Genres
, so pgx receives *[]string
type. It's your responsibility to use a type that pgx library can handle.
See https://pkg.go.dev/github.com/georgysavva/scany@v0.2.9/dbscan#hdr-NULLs_and_custom_types
and https://pkg.go.dev/github.com/georgysavva/scany@v0.2.9/pgxscan#hdr-Note_about_pgx_custom_types
Basically you need to use a type that implements sql.Scanner
interface or special pgx Decoder
interface as in the example you mentioned.
Something like that:
type CustomEnum []string
func (ce *CustomEnum) Scan(b []byte) error {
...
}
type Film struct {
ID string
Name string
ReleaseYear int
Genres CustomEnum
CoverImageId string
}
Thank you for replying! Will try this.
I forgot to add that it worked like a charm. Thanks again!
DBeaver type representation
Error:
The problem is clearly that scany doesn't work with custom enums. How to make it work like in https://github.com/jackc/pgx/blob/master/example_custom_type_test.go?