user6638204 user6638204 - 1 year ago 181
SQL Question

How to scan SQL array to []int64 in Go?

I am scanning an array of int from Postgres DB and it is returning as

. I need them in
, how can I convert them into
or how can I return them from the DB as
? In my query I am selecting using the Array function in Postgres:
where col1 is serial.

The error I am getting is:

unsupported Scan, storing driver.Value type []uint8 into type []int64

Answer Source

If you're using, just use Int64Array.

col1arr := []int64{}
arr := pq.Int64Array{}
err := rows.Scan(&arr)
// ...
col1arr = []int64(arr)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download