I have a struct Person which has a field AccessMode of type uint. In the Postgres database, the datatype of AccessMode is char(8).
I have written a custom Scan function for AccessMode which implements the Scanner Interface.
In the Scan function, it is received as a uint8 slice representation of ASCII string.
When the datatype of AccessMode is changed to varchar(8) in database, it is received as a string in the scan function. Following is the code
type Access uint
type Person struct {
AccessMode Access
}
func (a *Access) Scan(val interface{}) error {
if bb, ok := val.([]byte); ok {
return a.UnmarshalText(bb)
}
return errors.New("scan failed: data is not a byte slice")
}
Why is it received as a string in case of varchar and uint slice in case of char datatype in the scan function?