I use sqlx to select PostgreSQL boolan[] into a Golang structure, where the target structure value is []*bool.
type App struct { ApplicationID string `db:"application_id"` Name string `db:"name"` Description string `db:"description"` Replicated []*bool `db:"replicated"` } var apps []App err := trx.Select(&apps, "Select * From my_function()")
The error returned is: sql: Scan error on column index 3, name "replicated": Scan is not supported, driver.Value type []uint8 is stored as type *[]*bool
I've looked around but haven't found a solution yet. Any help would be greatly appreciated!
You can only scan content that implements the .Scanner
interface. You can define the structure as
import "github.com/lib/pq" type App struct { ApplicationID string `db:"application_id"` Name string `db:"name"` Description string `db:"description"` Replicated pq.BoolArray `db:"replicated"` }
where pq.BoolArray
is []bool
, or if you really need it to be []*bool
you can create your own type
type BoolArray []*bool
Then copy the code from here https://github. com/lib/pq/blob/2a217b94f5ccd3de31aec4152a541b9ff64bed05/array.go#L76 and modify as needed
The above is the detailed content of Scan error on column index 8, name 'replicated': Scan not supported, storing driver.Value of type uint8 as type **bool. For more information, please follow other related articles on the PHP Chinese website!