user6638204 user6638204 - 4 months ago 48
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


If you're using, just use Int64Array.

col1arr := []int64{}
arr := pq.Int64Array{}
err := rows.Scan(&arr)
// ...
col1arr = []int64(arr)