1

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

1 Answer 1

8

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

col1arr := []int64{}
arr := pq.Int64Array{}
err := rows.Scan(&arr)
// ...
col1arr = []int64(arr)
Sign up to request clarification or add additional context in comments.

4 Comments

can then I parse from pg.Int64Array to int64?
thank you that is what I needed, but I am getting an error: undefined: pq.Int64Array. I imported the library
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.
thanks I needed to update the library as you specified

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.