Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am scanning an array of int from Postgres DB and it is returning as []uint8. I need them in []int64, how can I convert them into []int64 or how can I return them from the DB as []int64? In my query I am selecting using the Array function in Postgres: Array(col1) where col1 is serial.

The error I am getting is:

unsupported Scan, storing driver.Value type []uint8 into type []int64
share|improve this question
up vote 2 down vote accepted

If you're using github.com/lib/pq, just use Int64Array.

col1arr := []int64{}
arr := pq.Int64Array{}
err := rows.Scan(&arr)
// ...
col1arr = []int64(arr)
share|improve this answer
    
can then I parse from pg.Int64Array to int64? – user6638204 Dec 1 at 9:33
    
@user6638204 See edit. – Ainar-G Dec 1 at 9:40
    
thank you that is what I needed, but I am getting an error: undefined: pq.Int64Array. I imported the library – user6638204 Dec 1 at 10:00
    
How did you import the library? If import _ "github.com/lib/pq" then remove the _. If that doesn't help, update it with go get -u github.com/lib/pq. – Ainar-G Dec 1 at 10:02
    
thanks I needed to update the library as you specified – user6638204 Dec 1 at 10:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.