I try to use ‘numeric’ type in posgres in Go app

Environments

  • go version go1.14.6 darwin/amd64
  • github.com/lib/pq v1.0.0
  • postgres:9.6

Table

create table sensor(
  id serial primary key,
  value numeric
);

Go app

err := db.QueryRow(`select id, value from sensor where id = $1`, id).Scan(&n)
if err != nil{
  return err
}
number, err := strconv.ParseFloat(string(n), 64)
if err != nil{
  return nil, fmt.Errorf("invalid string, parse, failed")
}
// number is Numeric value
print(number)

Ref

Issue
Why does Go treat a Postgresql numeric & decimal columns as []uint8?