In my data there is no null value, thus I can't explain the Scan error...
import (
"fmt"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
"log"
)
...
func dispatch[T chkRecord](db *sqlx.DB, table []T, query) error {
err := db.Select(&table, query)
if err != nil {
return err //Scan error on column index 5...converting NULL to int is unsupported
}
....
Why is that ? A bit of clarification about the context. The &table is not a regular db table,with possible NULLABLE fields, but a view and the Scan error ... fires on a calculated field.
The problem is, in database you have
NULLvalue for a particular column but sqlx doesn't know how to assign it to your struct one solution is to usepointertypes in your table struct .Considering Name is the field in your db which hasNULLvaluesIf the field Name in your struct is a pointer type, like
*string, then sqlx will handleNULLvalues from the database by setting the pointer tonil.