Search code examples
postgresqlgopgx

Error when scanning Postgres float4: cannot assign 5000 into pgtype.Float4


Query:

`select "number" from "person"`

Here is the code where am iterating over a row. number is of type float4 in Postgres. I am using pgtype.Float4 for scanning.

    for rows.Next() {
        var number pgtype.Float4
        err := rows.Scan(number)
        if err != nil {
            panic(err)
        }
    }

I am getting the following error:

panic: can't scan into dest[2]: cannot assign 5000 into pgtype.Float4

What might be the problem? Any suggestion is welcome. Thank you in advance.


Solution

  • I simply missed & before my variable name in .Scan().