我试图UUID从 PostgreSQL 数据库中获取一个数组,这给出了以下错误:
sql: Scan error on column index 0: unsupported Scan, storing driver.Value type []uint8 into type *[]string
获取单个UUID没有问题,但是当它是 an 时array,该Scan函数将元素的类型推断为uint8。
是否有解决方法/解决方案?或者我应该重新考虑我的数据库?
代码 :
func FetchListIdsForUser(id string, db *sql.DB) ([]string, error) {
// where the results will be stored
var (
lists []string
)
// statement prep
stmt, err := db.Prepare("select lists from users where object_id = $1")
if err != nil {
formattedError := er.New("FetchListIdsForUser SQL Select: " + err.Error())
log.Println(formattedError)
return nil,formattedError
}
defer stmt.Close()
// query happening
rows, err := stmt.Query(id)
if err != nil {
formattedError := er.New("FetchListIdsForUser SQL Query: " + err.Error())
log.Println(formattedError)
return nil,formattedError
}
defer rows.Close()
// for each row
for rows.Next() {
// scan : this is where the error happens.
err := rows.Scan(&lists)
if err != nil {
formattedError := er.New("FetchListIdsForUser SQL Scan: " + err.Error())
log.Println(formattedError)
return nil,formattedError
}
return lists,nil
}
err = rows.Err()
if err != nil {
formattedError := er.New("FetchListIdsForUser: " + id + " Does Not Exist")
log.Println(formattedError)
return nil,formattedError
}
return nil,er.New("FetchListIdsForUser: " + id + " Does Not Exist")
}
慕慕森
相关分类